【问题标题】:Rollback a committed transaction回滚已提交的事务
【发布时间】:2013-11-20 02:44:33
【问题描述】:

有什么办法可以rollbackoracle 11g中的一个已提交事务

我在数据库中创建了一个delete from table 并提交了它,现在我想rollback 提交的更改。有什么办法吗?

【问题讨论】:

  • 提交后没有回滚。它要么是回滚 要么是 提交。
  • 有一些闪退的概念,但是我无法使用......
  • 你不了解这个概念或者你没有闪回的权利?

标签: sql oracle oracle11g


【解决方案1】:

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

注意:此操作的成功与否取决于undo_retention 参数的值(默认900 秒)- undo 信息在undo 表空间中保留的时间段(可自动减少)。

/* 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

【讨论】:

【解决方案2】:

使用这个查询

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'));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-24
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多