Oracle REF动态游标使用

--(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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值