我有PL/SQL代码,其中在执行插入到表1中并基于某些条件从表2中删除,如果删除成功,则提交所有以上的staments并插入在表3中,状态为'cond_true'else回滚所有上述事务并插入到表3'cond_false'中。如果在此代码中使用提交和回滚,它将关闭打开的光标,并且必须重新为每个光标重新迭代或失败,并且没有光标打开状态。使用roolback/commit将所有光标聚焦,如何超过
OPEN cursor1;
Loop
fetch cursor1 into tbls;
exit when cursor1%notfound;
execute immediate INSERT INTO table1 SELECT * FROM table2;
-- commit only if below condition is true else rollback;
BEGIN
IF some_condition THEN
-- this condition will become true only after the above insert is executed successfully for all rows
execute immediate DELETE FROM table2 where some_condition2;
INSERT INTO table3 values('contition_true');
-- commit;
ELSE
INSERT INTO table3 values('contition_false');
--- first rollback the first insert and then commit only this statement;
END IF;
END;
END LOOP;
close cursor1;
什么让你认为光标在提交/回滚时关闭?另外,在这个特定的例子中,光标的点是什么?您不会引用循环内的光标。 – Boneist
在oracle回滚和提交中,关闭所有打开的游标。在上面的例子中,游标包含table1和table2的表名 –