我想看看更新锁是如何在dml (删除/更新)操作时帮助最小化错误的。
declare
cursor update_lock is select empno from emp where deptno=&no for update of sal;
num number;
begin
--for i in update_lock loop
--end loop;
open update_lock;
loop
fetch update_lock into num;
exit when update_lock%notfound;
dbms_output.put_line(num);
end loop;
update emp set sal=sal+10 where current of update_lock;
close update_lock;
end;我用非常简单的代码来检查,它是如何工作的。但是,它显示了无效的ROWID。有谁可以帮我?
发布于 2013-03-26 20:01:34
您的循环正在遍历emp for deptno=&no中的所有行,而不更新它们。当您到达结果集的末尾(最后一行一次)时,exit when udpate_lock%notfound会触发并跳出循环,跳到update语句。
此时,游标无效。你已经超越了最后一排。因此,update [...] where current of将失败-- update_lock没有current of,游标不在一行上。
https://dba.stackexchange.com/questions/37617
复制相似问题