Oracle誤刪數據的恢復,分為兩種方法:SCN和時間戳兩種方法恢復。
一、通過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; //允許更改時間戳
找出刪除的數據:select * from 表名 as of timestamp to_timestamp('刪除時間點','yyyy-mm-dd hh24:mi:ss')
把刪除的數據重新插入原表: insert into 表名 (select * from 表名 as of timestamp to_timestamp('刪除時間點','yyyy-mm-dd hh24:mi:ss'));
select * from t_xxx as of timestamp (systimestamp - interval '10' minute)