【发布时间】:2016-05-23 06:54:29
【问题描述】:
我有 PL/SQL 代码,其中我正在执行插入到表 1 并根据某些条件从表 2 中删除,如果删除成功,则提交所有上述语句并插入表 3,状态为“cond_true”else 回滚所有上述事务并插入 table3 'cond_false' 。如果在此代码中使用了提交和回滚,它将关闭打开的游标,并且必须再次为每个游标重新迭代,否则失败且没有游标打开状态。
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;
【问题讨论】:
-
是什么让您认为光标在提交/回滚时关闭?另外,在这个特定示例中光标的意义何在?您没有引用循环内的光标。
-
在 oracle 回滚和提交中,关闭所有打开的游标。在上述情况下,游标包含 table1 和 table2 的表名
标签: plsql