失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > oracle游标添加数据 Oracle使用游标更新数据

oracle游标添加数据 Oracle使用游标更新数据

时间:2018-10-25 19:28:18

相关推荐

oracle游标添加数据 Oracle使用游标更新数据

1. 使用游标修改数据

定义一个游标,游标名称为 mycursor

更新scott用户中emp表中empno为7369的销售额

-- Created on /11/30 by ZHANW

declare

he emp%rowtype;

cursor mycursor(pid integer) is select * from emp where empno = pid for update;

begin

open mycursor(7369);

while(true) loop

fetch mycursor into he;

exit when mycursor%notfound;

update emp set sal = 1111 where current of mycursor;

end loop;

end;

-- Created on /11/30 by ZHANW

declare

he emp%rowtype;

cursor mycursor(pid integer) is select * from emp where empno = pid for update;

begin

open mycursor(7369);

while(true) loop

fetch mycursor into he;

exit when mycursor%notfound;

delete from emp where current of mycursor;

end loop;

end;

注意:delete语句一定要写在exit后面,不然可能会报错。

优化:在定义游标时,可以在for update 后面添加 of 字段或者nowait。

如果觉得《oracle游标添加数据 Oracle使用游标更新数据》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。