使用隐式保存点回滚数据库更改? - 甲骨文

时间:2012-02-16 20:47:24

标签: oracle oracle11g

我可以使用隐式保存点回滚对数据库的更改吗?我最终通过我想要恢复的Java代码进行了更改(INSERTs)。

2 个答案:

答案 0 :(得分:3)

您可以使用How to COMMIT, ROLLBACK Oracle Transactions中列出的SAVEPOINT。

这是来自它的SAVEPOINT片段......

SAVEPOINT

Specify a point in a transaction to which later you can roll back.

Example

insert into emp (empno,ename,sal) values (109,’Sami’,3000);
savepoint a;
insert into dept values (10,’Sales’,’Hyd’);
savepoint b;
insert into salgrade values (‘III’,9000,12000);

Now if you give

rollback to a;

Then  row from salgrade table and dept will be roll backed. Now you can commit the row inserted into emp table or rollback the transaction.

If you give

rollback to b;

Then row inserted into salgrade table will be roll backed. Now you can commit the row inserted into dept table and emp table or rollback to savepoint a or completely roll backed the transaction.

If you give

rollback;

Then the whole transactions is roll backed.

If you give

commit;

Then the whole transaction is committed and all savepoints are removed.

答案 1 :(得分:3)

看看Using Oracle Flashback Technology。假设您的数据库已经设置好,那么您可以在插入之前闪回一段时间。如果其他用户也在更新此表,请小心。此外,如果您犯了错误并将手动闪回,我们建议您使用它,我不会将其构建到任何代码中以自动执行此操作。