加入oracle表值函数

时间:2011-07-20 15:01:28

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

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

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

3 个答案:

答案 0 :(得分:11)

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

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 :(得分:0)

也许这对你有用......

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

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

myFunc使用table_name.OBJID字段来匹配某些记录并执行任何操作...

答案 2 :(得分:0)

SELECT a.*, b.*
from table_name a cross join table ( myFunc(a.id) ) b