回滚已提交的事务

时间:2013-11-08 06:47:39

标签: sql oracle oracle11g

rollback

中有oracle 11g已提交的交易吗?

我在db中创建了delete from table并提交了它,现在我想rollback提交的更改。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:28)

您无法回滚已经提交的内容。在这种特殊情况下,作为最快的选项之一,您可以执行的操作是针对已删除行的表发出闪回查询并将其插回。这是一个简单的例子:

注意:此操作的成功取决于undo_retention参数的值(默认为900秒) - 在撤消期间保留撤消信息的时间段(可以自动缩减)表空间。

/* our test table */
create table test_tb(
   col number
);
/* populate test table with some sample data */
insert into test_tb(col)
   select level
     from dual
  connect by level <= 2;

select * from test_tb;

COL
----------
         1
         2
/* delete everything from the test table */    
delete from test_tb;

select * from test_tb;

no rows selected

将已删除的行重新插入:

/* flashback query to see contents of the test table 
  as of specific point in time in the past */ 
select *                                   /* specify past time */
  from test_tb as of timestamp timestamp '2013-11-08 10:54:00'

COL
----------
         1
         2
/* insert deleted rows */
insert into test_tb
   select *                                 /* specify past time */  
    from test_tb as of timestamp timestamp '2013-11-08 10:54:00'
   minus
   select *
     from test_tb


 select *
   from test_tb;

  COL
  ----------
          1
          2