今天我遇到了“FETCH OUT OF SEQUENCE”ORA-01002。我做了很多研究,我开始了解到,当我们这样做时,这是很常见的。
- 当我们已经关闭游标时尝试获取。
- 用于更新和提交。
我的要求是,如果处理成功,则提交每 500 条记录,如果出现任何问题,则回滚所获取的 500 条记录。
这两个我都没有做过。我还发现由于ROLLBACK而发生了乱序取取;
我还缩小了这种情况实际发生的时间。仅当第一组记录发生回滚时才会发生这种情况。
loop
Fetch c1 bulk collect into type1 limit 500;
exit when type1.count=0;
forall in i..type1.count save exceptions
insert into the table.
do something.....
the computation goes on;
Commit;
exception when others then
for i in 1..sql%bulk_exceptions loop
Do somthing...
end loop;
rollback; => Fetch out of seq happens here...
end loop;
仅当前 500 条记录失败并且我发出回滚命令时,才会发生乱序获取。当前 500 条记录被提交并且接下来获取的 500 条记录被回滚时,它不会给出 ora-01002。
它这样做的任何原因。请建议是否有任何方法可以避免 ora-01002 错误。
抱歉,由于公司政策的原因,无法在此发布代码。但上面给出的伪代码就是编码的样子。
其他信息 -> 如果我以这种方式执行程序,那么我不会收到错误“ORA-01002”。
loop
Fetch c1 bulk collect into type1 limit 500;
exit when type1.count=0;
COMMIT; => IF I ADD COMMIT HERE ORA-01002 doesnt appear.
forall in i..type1.count save exceptions
insert into the table.
do something.....
the computation goes on;
Commit;
exception when others then
for i in 1..sql%bulk_exceptions loop
Do somthing...
end loop;
rollback; => Fetch out of seq happens here...
结束循环;
最佳答案
当您以这种方式处理记录时,您不应该在处理过程中进行像这样的提交
/回滚
。 回滚
使当前光标无效。无论如何,您应该在 500 条记录之后提交,并处理异常。
一旦回滚,Oracle 就不可能记忆起其光标应在的位置。
如 this example 的语句 7 所示,您应该处理 FORALL
的单一异常,以防万一
--- declare exception
failure_in_forall EXCEPTION;
PRAGMA EXCEPTION_INIT (failure_in_forall, -24381);
...
-- handle it
EXCEPTION
WHEN failure_in_forall
...
然后您的良好记录将被处理和提交,不良记录将在稍后审核和处理
关于sql - 获取乱序 <ora-01002> 回滚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42294780/