回滚过程所做的更改

时间:2014-03-10 10:43:30

标签: oracle

我有一个程序myProcedure

create or replace
procedure myProcedure as 
begin
--some checking goes here
  INSERT INTO table1 VALUES..
--some checking goes here
   DELETE FROM table2;
end myProcedure;

我已调用此过程并且执行时没有任何错误。 我可以Rollback此程序所做的更改吗?

1 个答案:

答案 0 :(得分:0)

我猜你正在寻找SAVEPOINT。保存点保存事务状态并帮助回滚到指定的时间点。

create or replace
procedure myProcedure as 
begin
--some checking goes here
  INSERT INTO table1 VALUES..
  SAVEPOINT my_savepoint;
--some checking goes here
  DELETE FROM table2;
exception
   WHEN DUP_VAL_ON_INDEX THEN
      ROLLBACK TO do_insert;
      DBMS_OUTPUT.PUT_LINE('Insert has been rolled back');
end myProcedure;

检查Oracle文档:

Example 6-38, "Using SAVEPOINT With ROLLBACK"

Example 6-39, "Reusing a SAVEPOINT With ROLLBACK"