关于数据库中的表被delete后如何恢复

关于表数据delete后如何恢复

今天在开发中需要进行delete掉整张表的操作,为了更好调试,我觉得得先查好数据怎么恢复。

那么表数据delete掉后怎么恢复呢?

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

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

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

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

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

select * from 表名 as of timestamp to_timestamp('2021-02-20 11:54:58','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')

大功告成,数据恢复成功;

注意
但是也可能会出现问题,比如报错:ORA-08189:未启用行移动功能,不能闪回表;
不要怕,这个很简单;

alter table 表名 enable row movement

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

alter table inspur enable row movement

猜你喜欢

转载自blog.csdn.net/Liamcsl/article/details/114198102