cursor和sys_refcursor

本文探讨了在SQL操作中使用sys_refcursor与cursor两种方法进行数据读取的差异,重点介绍了如何确保数据一致性及通过一致性读取进行验证的方法。
----------------sys_refcursor---------------
declare
   cur   sys_refcursor;
   cur_e  test1.id%type;
begin
   open cur for
       select id from test1;
   insert into test1 (id) values (2);  --cur读取不到新增加的数据2
   commit;
   loop
       fetch cur into cur_e;
       exit when cur %notfound;
       dbms_output.put_line(cur_e);
   end loop;
-----------------cursor-----------------
declare
   cursor cur is select id from test1;
   cur_e  cur%rowype;
begin
   insert into test1 (id)values(2);
   commit;
   for cur_e in cur loop  --能读取新增加的数据2
       exit when cur %notfound;
       dbms_output.put_line(cur_e.id);
   end loop;
end;
-----------------一致性读,可调式进行验证-------------
create or replace package body pkg as
   procedure pro is
       mycur  sys_refcursor;
       row_mycur  mas%rowtype;
   begin
       open mycur for
           select * from mas; --一致性读
       loop
           fetch mycur into row_mycur;
           exit when mycur%notfound;
           dbms_output.put_line(row_mycur.name);
       end loop;
   end;
end pkg;



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/30201626/viewspace-1813749/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/30201626/viewspace-1813749/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值