Parece que desea fusionar un número desconocido de SYS_REFCURSOR
conjuntos de resultados en uno grande. Si conoce la estructura del cursor devuelto por spSelect_Inv_Search
puede hacer esto con una función segmentada intermedia.
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;
/
Los tipos se pueden definir aquí, no tienen que estar en el nivel de SQL, ya que nunca necesitará hacer referencia a ellos fuera del paquete.
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;
/
Luego, para ejecutar, lo que puede hacer fuera del paquete a pesar de los tipos utilizados para la etapa intermedia, puede hacer esto para probar en SQL*Plus o SQL Developer:
var rc refcursor;
exec p.proc3(:rc);
print rc;
Para mi base de datos esto da:
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
Obviamente, esto es muy artificial, ya que lo haría como una sola consulta, pero asumo que su procedimiento interno debe hacer algo más complicado.