How to create a connection between the results of two PL / SQL functions?

I have two functions that return a TYPE, ie:

CREATE OR REPLACE FUNCTION myUser.f_myFunction
(
    myId IN RAW := NULL
) RETURN myUser.myType
AS
    ResultTable myUser.myType;
BEGIN
    ...
    -- fill ResultTable
    ...

    RETURN ResultTable;
END;

Now I want to join them in the instructions SELECT:

SELECT *
FROM myUser.f_myFunction1() f1
JOIN myUser.f_myFunction2() f2 ON f1.xy = f2.yz;

But if I include a function in a statement SELECT, I get an error:

SELECT * FROM myUser.f_myFunction();
                                 *
ERROR in Line 1:
ORA-00933: SQL command not properly ended
    ORA-04044: procedure, function, package, or type is not allowed here

.

EDIT: Embedding a function call in a sentence TABLE()gives the following error:

SELECT * FROM TABLE(myUser.f_myFunction())
              *
ERROR at line 1:
ORA-22905: cannot access rows from a non-nested table item

Then I tried to apply it, but:

SELECT * FROM TABLE(CAST(myUser.f_myFunction() AS myUser.myType))
                             *
ERROR at line 1:
ORA-22907: invalid CAST to a type that is not a nested table or VARRAY

and

SELECT * FROM TABLE(CAST(myUser.f_myFunction() AS myUser.myTypeTable))
                             *
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got myUser.myType

.

EDIT 2: Here are the type definitions (sorry, they should be included before):

CREATE TYPE myUser.myType AS OBJECT (
    ....
);

CREATE TYPE myUser.myTypeTable IS TABLE OF myUser.myType;

.

EDIT 3: . It works as follows:

CREATE OR REPLACE FUNCTION myUser.f_myFunction
(
    myId IN RAW := NULL
) RETURN myUser.myTypeTable
AS
    ResultTable myUser.myTypeTable;
BEGIN

    SELECT myUser.myType(x.Column1, x.Column2, ...)
        BULK COLLECT INTO ResultTable
        FROM myUser.myTable x
        WHERE ...

    RETURN ResultTable;
END;
+4
source share
1 answer

: 1) 2) . 3) .

create or replace type myType as object
(
    wx number,
    xy number
);


CREATE OR REPLACE FUNCTION f_myFunction
(
    myId IN RAW := NULL
) RETURN myType
AS
    ResultTable myType := myType(1, 2);
BEGIN
    RETURN ResultTable;
END;
/

1.

, TABLE CAST . .

create or replace type myType_nt is table of myType;

CREATE OR REPLACE FUNCTION f_myFunction_nt
(
    myId IN RAW := NULL
) RETURN myType_nt
AS
    ResultTable myType_nt := myType_nt(myType(1, 2));
BEGIN
    RETURN ResultTable;
END;
/

select wx, xy from table(f_myFunction_nt());

WX  XY
--  --
1   2

2:

, . . .

select wx, xy from
(
    select f_myFunction().wx wx, f_myFunction().xy xy from dual
);

WX  XY
--  --
1   2

, . Oracle . . SQL.

SQL> select * from (select f_myFunction() from dual);

F_MYFUNCTION()(WX, XY)
-----------------------------------------------------
MYTYPE(1, 2)

, , .

SQL> select wx, xy from (select f_myFunction() from dual);
select wx, xy from (select f_myFunction() from dual)
           *
ERROR at line 1:
ORA-00904: "XY": invalid identifier

3.

. , .

create or replace function get_wx(p_myType myType) return number is
begin
    return p_myType.wx;
end;
/

create or replace function get_xy(p_myType myType) return number is
begin
    return p_myType.xy;
end;
/

select get_wx(asdf) wx, get_xy(asdf) xy
from (select f_myFunction() asdf from dual);

WX  XY
--  --
1   2
+2

All Articles