我有两个函数都返回 a TYPE
,即:
CREATE OR REPLACE FUNCTION myUser.f_myFunction
(
myId IN RAW := NULL
) RETURN myUser.myType
AS
ResultTable myUser.myType;
BEGIN
...
-- fill ResultTable
...
RETURN ResultTable;
END;
现在我想和他们一起SELECT
发表声明:
SELECT *
FROM myUser.f_myFunction1() f1
JOIN myUser.f_myFunction2() f2 ON f1.xy = f2.yz;
但是如果我在语句中包含一个函数SELECT
,我会得到一个错误:
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
.
编辑:将函数调用嵌套在TABLE()
子句中会出现以下错误:
SELECT * FROM TABLE(myUser.f_myFunction())
*
ERROR at line 1:
ORA-22905: cannot access rows from a non-nested table item
然后我尝试投射它,但是:
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
和:
SELECT * FROM TABLE(CAST(myUser.f_myFunction() AS myUser.myTypeTable))
*
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got myUser.myType
.
编辑2:这是类型的定义(对不起,应该早点包括它们):
CREATE TYPE myUser.myType AS OBJECT (
....
);
CREATE TYPE myUser.myTypeTable IS TABLE OF myUser.myType;
.
编辑3:让它像这样工作:
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;