【问题标题】:Join to an oracle table valued function加入 oracle 表值函数
【发布时间】:2011-10-09 11:46:48
【问题描述】:

是否可以加入 Oracle 表值函数?

SELECT 
   *
FROM 
  SOME_TABLE a
INNER JOIN 
  TABLE(GET_TABLE_LIST()) b ON = a.COL_A = b.COL_A

【问题讨论】:

  • GET_TRFRMENGMACHIENINFOTse 是什么?
  • 抱歉,剪切/粘贴错误......它们是 GET_TRFM...... 函数中使用的类型。仅显示输出将来自表值函数。

标签: oracle inner-join user-defined-functions


【解决方案1】:

你可以,是的。由于我没有您的get_TrfrmEngMachineInfoT 函数,我将创建自己的集合并将其加入SCOTT 架构中的EMP

SQL> create or replace type typ_person
  2      as object (
  3        person_id number,
  4        person_name varchar2(30)
  5      );
  6  /

Type created.

SQL> create or replace type tbl_person
  2    as table of typ_person;
  3  /

Type created.

SQL> ed
Wrote file afiedt.buf

  1  create or replace function get_person_list
  2    return tbl_person
  3  is
  4    l_people tbl_person;
  5  begin
  6    select typ_person( empno, ename )
  7      bulk collect into l_people
  8      from emp;
  9    return l_people;
 10* end;
SQL> /

Function created.

SQL> select p.*
  2    from emp e
  3         join table( get_person_list() ) p on (p.person_id = e.empno);

 PERSON_ID PERSON_NAME
---------- ------------------------------
      7623 PAV
      7369 smith
      7499 ALLEN
      7521 WARD
      7566 JONES
      7654 MARTIN
      7698 BLAKE
      7782 CLARK
      7788 SCOTT
      7839 KING
      7844 TURNER
      7876 ADAMS
      7900 SM0
      7902 FORD
      7934 MILLER
      1234 FOO

16 rows selected.

【讨论】:

  • 贾斯汀你有每一个问题的解决方案+1,不能做更多;)
【解决方案2】:

也许这对你有用...

SELECT table_name.*, myFunc(table_name.OBJID) as new_field_name from table_name

这将从table_name 表中选择所有内容并将函数的结果添加到新集合中。

myFunc 使用table_name.OBJID 字段来匹配一些记录并做任何事情......

【讨论】:

    【解决方案3】:
    SELECT a.*, b.*
    from table_name a cross join table ( myFunc(a.id) ) b
    

    【讨论】:

    • 请不要只发布代码作为答案,还要解释您的代码的作用以及它如何解决问题的问题。带有解释的答案通常更有帮助,质量更高,更有可能吸引投票。
    猜你喜欢
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 2022-11-14
    相关资源
    最近更新 更多