您似乎想将未知数量的SYS_REFCURSOR
结果集合并为一个大的结果集。如果您知道从中返回的游标的结构,则spSelect_Inv_Search
可以使用中间流水线函数来执行此操作。
create package p as
type tmp_rec_type is record (owner all_objects.owner%type,
object_type all_objects.object_type%type,
objects number);
type tmp_rec_table is table of tmp_rec_type;
procedure proc1(p_owner in varchar2, p_cursor out sys_refcursor);
function func2 return tmp_rec_table pipelined;
procedure proc3(p_cursor out sys_refcursor);
end;
/
可以在此处定义类型,它们不必处于 SQL 级别,因为您永远不需要在包之外引用它们。
create package body p as
procedure proc1(p_owner in varchar2, p_cursor out sys_refcursor) as
begin
open p_cursor for select owner, object_type, count(*)
from all_objects
where owner = p_owner
group by owner, object_type;
end;
function func2 return tmp_rec_table pipelined as
cursor c1 is select distinct owner
from all_tables where owner in ('SYS','SYSTEM');
tmp_cursor sys_refcursor;
tmp_rec tmp_rec_type;
begin
for r1 in c1 loop
proc1(r1.owner, tmp_cursor);
loop
fetch tmp_cursor into tmp_rec;
exit when tmp_cursor%notfound;
pipe row(tmp_rec);
end loop;
end loop;
end;
procedure proc3(p_cursor out sys_refcursor) as
begin
open p_cursor for select * from table(func2);
end;
end p;
/
然后执行,尽管中间阶段使用了类型,但您可以在包外执行此操作,您可以执行此操作以在 SQL*Plus 或 SQL Developer 中进行测试:
var rc refcursor;
exec p.proc3(:rc);
print rc;
对于我的数据库,这给出了:
OWNER OBJECT_TYPE OBJECTS
------------------------------ ------------------- ----------------------
SYSTEM VIEW 1
SYSTEM TABLE 5
SYS VIEW 1056
SYS CONSUMER GROUP 2
SYS PROCEDURE 11
SYS FUNCTION 56
SYS SEQUENCE 1
SYS OPERATOR 6
SYS EVALUATION CONTEXT 1
SYS TABLE 13
SYS WINDOW GROUP 1
SYS PACKAGE 162
SYS WINDOW 2
SYS TYPE 529
SYS JOB CLASS 1
SYS SCHEDULE 1
这显然是非常人为的,因为您将其作为单个查询执行,但我假设您的内部过程需要做一些更复杂的事情。