----------------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/
,如需转载,请注明出处,否则将追究法律责任。