ITPub博客

首页 > 数据库 > Oracle > cursor和sys_refcursor

cursor和sys_refcursor

原创 Oracle 作者:masheng0925 时间:2015-10-11 12:18:22 0 删除 编辑
----------------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博客 ” ,链接:https://blog.itpub.net/30201626/viewspace-1813749/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2015-04-11

  • 博文量
    43
  • 访问量
    44267