如何从一个存储过程中从SYS_REFCURSOR获取数据并在另一个存储过程中使用它?

dee*_*dee 7 sql oracle stored-procedures cursor

我有一个存储过程,其下面的基本布局返回一个sys_refcursor作为结果集.(从技术上讲,它重新发布了四个,但为了清楚起见,我只说一个).结果集是临时表的选择.

procedure aProcedure
( C1 in out sys_refcursor
) is
begin
--populate Temp_Table here with a stored proc call;
OPEN C1 FOR
SELECT Cols
FROM TEMP_TABLE;
Run Code Online (Sandbox Code Playgroud)

我需要使用不同的存储过程将C1中的结果集插入到永久表中.这是可行的还是我需要重新构建结果集?

我已经能够找到有关使用oracle之外的游标和结果集的信息,但不能在其内部使用它们.

我知道从第一个存储过程执行插入可能是有意义的,但这不是我真正需要它发生的方式.永久保存结果集是一项可选要求.

感谢任何有用的信息.

Jus*_*ave 16

假设调用者知道aProcedure正在打开的游标的结构,你可以这样做.

declare
  l_rc sys_refcursor;
  l_rec temp_table%rowtype;
begin
  aProcedure( l_rc );
  loop
    fetch l_rc
     into l_rec;
    exit when l_rc%notfound;

    dbms_output.put_line( l_rec.col1 );
  end loop;
  close l_rc;
end;
/
Run Code Online (Sandbox Code Playgroud)

如果无法获取记录类型,还可以获取许多其他标量局部变量(数字和类型必须与列表中aProcedure指定的列数和类型相匹配SELECT).就我而言,我定义aProcedure了返回两个数字列

declare
  l_rc sys_refcursor;
  l_col1 number;
  l_col2 number;
begin
  aProcedure( l_rc );
  loop
    fetch l_rc
     into l_col1, l_col2;
    exit when l_rc%notfound;
    dbms_output.put_line( l_col1 );
  end loop;
  close l_rc;
end;
Run Code Online (Sandbox Code Playgroud)