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
...
...
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;