Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Join to an oracle table valued function

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

SELECT 
   *
FROM 
  SOME_TABLE a
INNER JOIN 
  TABLE(GET_TABLE_LIST()) b ON = a.COL_A = b.COL_A
like image 510
Ryan Fisch Avatar asked Jul 20 '11 15:07

Ryan Fisch


People also ask

How do you join a table with a table valued function in SQL?

SQL Server does have a solution for this called CROSS APPLY. If you use CROSS APPLY for INNER JOINS and OUTER APPLY for LEFT OUTER JOINS, then you have the ability to create a join between two table valued expressions, which in my case is a TABLE VARIABLE and the results of a TABLE VALUED FUNCTION.

Can we join a table with a function?

However, JOIN operations cannot be used to join a table with the output of a table valued function. APPLY operators are used for this purpose. There are two main types of APPLY operators. 1) CROSS APPLY and 2) OUTER APPLY.

Can we use table valued function in join in SQL Server?

Description. The simple definition of the table-valued function (TVF) can be made such like that; a user-defined function that returns a table data type and also it can accept parameters. TVFs can be used after the FROM clause in the SELECT statements so that we can use them just like a table in the queries.

What is (+) in Oracle join?

The (+) operator indicates an outer join. This means that Oracle will still return records from the other side of the join even when there is no match.

What does (+) mean in SQL JOIN?

Outer Join Operator (+) - Oracle to SQL Server Migration Oracle outer join operator (+) allows you to perform outer joins on two or more tables. Quick Example: -- Select all rows from cities table even if there is no matching row in counties table SELECT cities.


1 Answers

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.
like image 125
Justin Cave Avatar answered Sep 20 '22 06:09

Justin Cave