Oracle数据库使用delete误删数据恢复

恢复方式转自:https://blog.csdn.net/zl834205311/article/details/86605494

一. 根据时间恢复:

1、查询数据库当前时间(目的是为了检查数据库时间是否与你电脑时间相近,避免时间不同而将数据恢复到错误时间点)

 select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual; 

2、查询删除数据时间点之前的数据

select * from 表名 as of timestamp to_timestamp('2016-08-11 16:12:11','yyyy-mm-dd hh24:mi:ss');

(若没有数据 ,将时间继续提前)

3、恢复数据

 flashback table 表名 to timestamp to_timestamp('2016-08-11 16:12:11','yyyy-mm-dd hh24:mi:ss'); 

4、可能会出现问题,比如:

(1) 报错:ORA-08189:未启用行移动功能,不能闪回表;

 alter table 表名 enable row movement; 

然后再次执行上面SQL即可;

(2) 报错: ORA-08194: 在实体化视图上不允许闪回表操作;

第一步: 得到一个存有原数据表中记录的新表(新表的结构与原表一致)(摘录自:http://blog.itpub.net/24237320/viewspace-1060338/)

create table 新建表名 as select * from 要恢复数据的表名 as of timestamp to_timestamp('2016-08-11 16:12:11','yyyy-mm-dd hh24:mi:ss');

第二步: 将新表中的数据导入到原表中(原文链接:https://blog.csdn.net/weixin_39407700/article/details/80523156)

  不区分数据是否重复:

  insert into 要回复数据的表 select * from 新表 (这里可以输入过滤条件);  

  不导入重复数据:

insert into 要恢复数据的表 select * from 新表 where not exists (select * from 要回复数据的表 where 要回复数据的表 .id=新表.id)

  可以指定字段插入(不做阐述):

 insert into tableB (col1, col2, ...) SELECT col1, col2, ... FROM tableA; 

二. 根据数据库SCN恢复数据

1、查询当前数据库SCN号

 select current_scn from v$database;(不能执行的话,切换到sys用户或system用户查询) 

查询到的当前值为:91799986

2、缩小SCN号查询被删除表数据(若无数据继续缩小SCN,由于数据库操作不止一人,SCN号变化比较多,可以多缩小几个号)

 select * from 表名 as of scn 91799980; 

3、恢复数据

 flashback table 表名 to scn 91799980; 

恢复完成。

4、若报错:结果方案同上。

每日一点点

原文地址:https://www.cnblogs.com/xiao-lin-unit/p/14190447.html