TBo*_*ose 2 oracle plsql cursor
sys_refcursor我可以从普通游标打开带有值的值吗?
create or replace procedure test(C1 out sys_refcursor)
Lv_c1 as
Select * from table;
Begin
Open C1 for select * from lv_c1;
End;
Run Code Online (Sandbox Code Playgroud)
你不能。“普通”游标是一个 PL/SQL 变量,因此不能在 SQL 查询中使用。
但可以为游标变量的结果集打开游标:
create or replace package pack as
cursor cur is
select rownum attr_1 from dual connect by level<=3;
type rset is table of cur%rowtype;
procedure getCursor (rc out sys_refcursor);
end;
/
create or replace package body pack as
procedure getCursor (rc out sys_refcursor) is
rs rset;
begin
open cur;
fetch cur bulk collect into rs;
close cur;
open rc for select * from table (rs);
end;
end;
/
Run Code Online (Sandbox Code Playgroud)
执行及结果:
var rc refcursor
exec pack.getCursor (:rc)
ATTR_1
--------
row1
row2
row3
Run Code Online (Sandbox Code Playgroud)