17

有什么办法可以rollback提交交易oracle 11g

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

4

2 回答 2

36

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

注意:此操作的成功取决于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
于 2013-11-08T07:00:50.923 回答
0

使用此查询

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'));
于 2021-11-04T06:15:38.403 回答