天天看點

恢複oracle資料庫誤删資料

一、通過scn恢複删除

1、獲得目前資料庫的scn号

select current_scn from v$database; (切換到sys使用者或system使用者查詢)

查詢到的scn号為:1499223

2、查詢目前scn号之前的scn

select * from 表名 as of scn 1499220; (确定删除的資料是否存在,如果存在,則恢複資料;如果不是,則繼續縮小 scn号)

3、恢複删除且已送出的資料

flashback table 表名 to scn 1499220;

**二、通過時間恢複

1、查詢目前系統時間

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

2、查詢删除資料的時間點的資料

select * from 表名 as of timestamp to_timestamp(‘2013-05-29 15:29:00’,‘yyyy-mm-dd hh24:mi:ss’); (如果不是,則繼續縮小範圍)

3、恢複删除且已送出的資料

flashback table 表名 to timestamp to_timestamp(‘2013-05-29 15:29:00’,‘yyyy-mm-dd hh24:mi:ss’);

注意:如果在執行上面的語句,出現錯誤。可以嘗試執行 alter table 表名 enable row movement; //允許更改時間戳

或者insert into t_viradsl2 select * from t_viradsl2 as of timestamp to_Date('2011-01-19 15:28:00', 'yyyy-mm-dd hh24:mi:ss')             //已将誤删除資料插入表中**