sql - 回滚已提交的事务

标签 sql oracle oracle11g

有什么方法可以在rollback中执行oracle 11g提交的事务

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

最佳答案

您无法回滚已提交的内容。在这种特定情况下,作为最快的选项之一,您可以做的是对已从中删除行并将其插入的表进行闪回查询。这是一个简单的示例:

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

关于sql - 回滚已提交的事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19853150/

相关文章:

sql - 如何在单个查询中从 ActiveRecord 中的父项中选择唯一子项?

sql - 在 SQL 和查询中将日期转换为日期时间大于

分配给变量时的sql执行延迟

sql - 单个列的多个外键

oracle - "Scaling of decimal value resulted in data truncation"通过 ODBC

Oracle直接路径插入问题

c# - 减少 Oracle 中的解析调用

sql - 需要帮助从字符串中提取子字符串直到特定长度之前的最后一个空格

Oracle 插入返回

sql - 主键和唯一索引——由 SQL Developer 生成的 sql 脚本