--(1)强类型
select * from customer;
select * from dept;
declare
--声明游标类型 返回记录类型
type cur_ref1 is ref cursor return customer%rowtype;
type cur_ref2 is ref cursor return dept%rowtype;
--声明游标类型变量
my1 cur_ref1;
my2 cur_ref2;
--声明游标记录类型
v_t1 my1%rowtype;
v_t2 my2%rowtype;
begin
--打开游标
open my1 for select * from customer;
--提取游标的数据
loop
fetch my1 into v_t1;
exit when my1%notfound;
dbms_output.put_line(v_t1.name||'-->'||v_t1.location);
end loop;
--关闭游标
close my1;
--打开游标
open my2 for select * from dept;
--提取游标的数据
loop
fetch my2 into v_t2;
exit when my2%notfound;
dbms_output.put_line(v_t2.dname||'-->'||v_t2.loc);
end loop;
--关闭游标
close my2;
end;
--(2)弱类型
declare
--声明游标类型 返回记录类型
type cur_ref is ref cursor;
--声明游标类型变量
my cur_ref;
--声明游标记录类型
v_t1 customer%rowtype;
v_t2 dept%rowtype;
begin
--打开游标
open my for select * from customer;
--提取游标的数据
loop
fetch my into v_t1;
exit when my%notfound;
dbms_output.put_line(v_t1.name||'-->'||v_t1.location);
end loop;
--打开同一个游标
open my for select * from dept;
--提取游标的数据
loop
fetch my into v_t2;
exit when my%notfound;
dbms_output.put_line(v_t2.dname||'-->'||v_t2.loc);
end loop;
--关闭游标
close my;
end;
Oracle REF动态游标使用
最新推荐文章于 2023-04-03 16:15:52 发布