请高手指教: pl/sql中 一个存储过程返回游标,另一个存储过程调用那个过程获得游标并赋值个游标变量例如:
create or replace procedure pro_AAA ---是否可以这样返回游标???????
(
aid number,
cur_X out sys_recursor
)as
type mytype is ref cursor;
cur_Y mytype;
begin
open cur_Y for select * from table_Name;
cur_X:=cur_Y;
end pro_AAA;create or replace procedure pro_BBB
(
cur_X out sys_recursor
)as
type mytype is ref cursor;
cur_B mytype;
begin
cur_B:= 调用pro_AAA(...) 这里怎么办????
end pro_BBB;
create or replace procedure pro_AAA ---是否可以这样返回游标???????
(
aid number,
cur_X out sys_recursor
)as
type mytype is ref cursor;
cur_Y mytype;
begin
open cur_Y for select * from table_Name;
cur_X:=cur_Y;
end pro_AAA;create or replace procedure pro_BBB
(
cur_X out sys_recursor
)as
type mytype is ref cursor;
cur_B mytype;
begin
cur_B:= 调用pro_AAA(...) 这里怎么办????
end pro_BBB;
(
aid number,
cur_X out sys_recursor
)as
type mytype is ref cursor;
cur_Y mytype;
begin
open cur_Y for select * from table_Name;
cur_X:=cur_Y;
end pro_AAA; create or replace procedure pro_BBB
(
cur_X out sys_recursor
)as
type mytype is ref cursor;
cur_B mytype;
begin
--cur_B:= 调用pro_AAA(...) 这里怎么办????
PRO_AAA(V_AID, CUR_B); --这里接收游标
FOR X IN CUR_B LOOP
NULL; --这里对接收到的游标循环处理。
END LOOP;
/
end pro_BBB;
因为你用游标的目的是为了传输结果集
这种不同存储过程之间,你用游标还不如单独建一张表
一个存储过程生成结果到这张表,另外调用的存储过程从这张表里取数据
delcare
v_aa varchar2(10);--这个和table表中aa类型大小一样
cursor v_cur is select aa from table;
begin
open v_cur; --打开游标
fetch v_cur into v_aa; --取出第一条记录存入变量
while v_cur %found loop --循环判断,取数为空时退出
--对值进行处理
fetch v_cur into v_aa; --取下一条
end loop;
close v_cur; --关闭游标
end;
create or replace procedure pro_AAA(
aid number,
cur_X out sys_recursor --输出游标参数
)as
begin
open cur_X for select * from table_Name; --游标
end pro_AAA; create or replace procedure pro_BBB
(
)as
cur_B SYS_REFCURSOR;
begin
PRO_AAA(CUR_B); --这里接收游标
FOR X IN CUR_B LOOP
NULL; --这里对接收到的游标循环处理。
END LOOP;
/
end pro_BBB;