3.41 Oracle数据库恢复

Oracle数据库删除操作提交事务的回滚。Oracle误删数据的恢复,分为两种方法:SCN和时间戳两种方法恢复。
  1. 通过SCN恢复删除且已提交的数据(可修改30分钟以内)

    1. 获得当前数据库的SCN号
      1.  select current_scn from v$database; (切换到sys用户或system用户查询) 
      2.  查询到的SCN号为:1499223
    2. 查询当前SCN号之前的SCN
      1.  select * from 表名 as of scn 1499220; (确定删除的数据是否存在,如果存在,则恢复数据;如果不是,则继续缩小scn号)
    3. 恢复删除且已提交的数据
      1.   flashback table 表名 to scn 1499220;
      2. 如果报错, 提示ORA-08189: 因为未启用行移动功能, 不能闪回表 。一般来说出现这种错误,就是数据库表不支持闪回功能,修复很简单,开启即可。、
        1. 所以执行以下语句  再执行闪回。
        2. alter table pb_acc_user enable row movement;      成功闪回修改.
  2. 通过时间恢复删除且已提交的数据(默认可恢复30分钟以内)

    1. 查询当前系统时间
      1.    select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
    2. 查询删除数据的时间点的数据
      1.    select * from 表名 as of timestamp to_timestamp('2013-05-29 15:29:00','yyyy-mm-dd hh24:mi:ss');  (如果不是,则继续缩小范围)
    3. 恢复删除且已提交的数据
      1.     flashback table 表名 to timestamp to_timestamp('2013-05-29 15:29:00','yyyy-mm-dd hh24:mi:ss');
      2.     注意:如果在执行上面的语句,出现错误。可以尝试执行 alter table 表名 enable row movement; //允许更改时间戳
      3.    找出删除的数据:select * from 表名 as of timestamp to_timestamp('删除时间点','yyyy-mm-dd hh24:mi:ss')   
      4.    把删除的数据重新插入原表: insert into 表名 (select * from 表名 as of timestamp to_timestamp('删除时间点','yyyy-mm-dd hh24:mi:ss')); 
      5.   select * from t_xxx as of timestamp (systimestamp - interval '10' minute)
原文地址:https://www.cnblogs.com/Smileing/p/13759487.html