create or replace package p1 is
type mytype is
ref cursor;
procedure pro_p1(cur out mytype);
function fun_p1(str varchar2)
return varchar2;
end;
create or replace package body p1 is
procedure pro_p1(cur out mytype) is
begin
open cur for select * from tb_role;
end pro_p1;
function fun_p1(str varchar2)
return varchar2
is
stem_str varchar2(200);
begin
stem_str := 'Good Luck!';
stem_str := stem_str || str;
return stem_str;
end fun_p1;
end p1;
上面的包里面有个名为:pro_p1的过程.
我在pl/sql developer工具里面想打印出过程输出游标的值:
我尝试了2中方法:
方法一:
declare cur p1.mytype;
currow tb_role%rowtype;
begin
pro_getsamerole(cur);
if(cur%notfound) then
dbms_output.put_line('游标为空');
else
dbms_output.put_line('游标不为空');
loop fetch cur into currow;
exit when cur%notfound;
dbms_output.put_line(currow.id || currow.rolename);
end loop;
end if;
end;---此方法可行
方法二:
declare cur p1.mytype;
begin
pro_getsamerole(cur);
if(cur%notfound) then
dbms_output.put_line('游标为空');
else
dbms_output.put_line('游标不为空');
for cc in cur loop
dbms_output.put_line(cc.rolename);
end loop;
end if;
end;---此方法报错
方法二报错:cur不是过程或者尚未定义.
这个for循环怎么解决?求高人指点!