开发者

Join to an oracle table valued function

开发者 https://www.devze.com 2023-03-22 04:32 出处:网络
Is is possible to join to an Oracle table valued function? SELECT * FROM SOME_TABLE a INNER JOIN TABLE(GET_TABLE_L开发者_StackOverflowIST()) b ON = a.COL_A = b.COL_A

Is is possible to join to an Oracle table valued function?

SELECT 
   *
FROM 
  SOME_TABLE a
INNER JOIN 
  TABLE(GET_TABLE_L开发者_StackOverflowIST()) b ON = a.COL_A = b.COL_A


You can, yes. Since I don't have your get_TrfrmEngMachineInfoT function, I'll create my own collection and join it to the EMP table in the SCOTT schema

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.


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


Maybe this can work for you...

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

That will select everything from the table_name table and add the result of the function in to the new set.

myFunc uses table_name.OBJID field to match some records and do whatever...

0

精彩评论

暂无评论...
验证码 换一张
取 消