回滚已提交的事务

18

在Oracle 11g中,有没有一种方法可以回滚已提交的事务?

我在数据库中执行了delete from table操作并将其提交,现在我想要回滚已提交的更改。有没有办法做到这一点?


提交后就没有回滚了。只能选择回滚或提交。 - juergen d
有一些闪回的概念,但我无法使用它。 - Varun
你不了解这个概念,还是没有闪回的权限? - Pravin Satav
2个回答

38

已经提交的内容无法回滚。在这种情况下,你可以采用一个较快的方法:对于删除了行的表,可以使用闪回查询将它们重新插入。以下是一个简单的示例:

注意:此操作的成功取决于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

不明白这个解决方案是什么?我能恢复我的数据吗? - Varun
1
@Varun - 如果数据仍然存在于您的“UNDO”表空间中,是的。 - Justin Cave
1
有关闪回的更多信息,请访问http://docs.oracle.com/cd/B12037_01/appdev.101/b10795/adfns_fl.htm。 - Pravin Satav
2
另一种方法是使用FLASHBACK TABLE - 这听起来很相似,但实际上有很大的不同:http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9012.htm - Jeffrey Kemp

1
请使用以下查询。
SELECT * FROM employee AS OF TIMESTAMP 
   TO_TIMESTAMP('2003-04-04 09:30:00', 'YYYY-MM-DD HH:MI:SS')

然后将其插入到删除表中

INSERT  INTO  employee (SELECT * FROM employee AS OF TIMESTAMP 
   TO_TIMESTAMP('2003-04-04 09:30:00', 'YYYY-MM-DD HH:MI:SS'));

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接