king

oracle游标怎么关闭?

king Oracle 2022-07-01 716浏览 0

oracle游标怎么关闭?

1. 用open打开的,用close关闭

declare
cursor mycursor is
select * from emp for update;
myrecord emp%rowtype;
begin
open mycursor;
loop
fetch mycursor into myrecord;
exit when mycursor%notfound;
if (myrecord.sal=2000) then
update emp
set sal=2001
where current of mycursor;
end if;
end loop;
close mycursor;
commit;
end;

2. 用for 循环的,循环完了就自己关了

declare
cursor mycursor is
select * from emp;
begin
for i in mycursor
loop
dbms_output.put_line(i.job);
end loop;
end;


继续浏览有关 oracle 的文章
发表评论