在執(zhí)行維護計劃的時候,如果準備備份數(shù)據(jù)庫或者進行數(shù)據(jù)庫例行維護,誤操作導致oracle數(shù)據(jù)庫數(shù)據(jù)被刪除了,想知道有什么辦法能恢復,可以通過scn和時間戳兩種方法進行數(shù)據(jù)恢復。
恢復刪除的oracle數(shù)據(jù)分為兩種方法:
一、通過scn恢復刪除且已提交的數(shù)據(jù)
1、獲得當前數(shù)據(jù)庫的scn號
select current_scn from v$database; (切換到sys用戶或system用戶查詢)
查詢到的scn號為:1499223
2、查詢當前scn號之前的scn
select * from 表名 as of scn 1499220; (確定刪除的數(shù)據(jù)是否存在,如果存在,則恢復數(shù)據(jù);如果不是,則繼續(xù)縮小scn號)
3、恢復刪除且已提交的數(shù)據(jù)
flashback table 表名 to scn 1499220;
二、通過時間恢復刪除且已提交的數(shù)據(jù)
1、查詢當前系統(tǒng)時間
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
2、查詢刪除數(shù)據(jù)的時間點的數(shù)據(jù)
select * from 表名 as of timestamp to_timestamp('2013-05-29 15:29:00','yyyy-mm-dd hh24:mi:ss'); (如果不是,則繼續(xù)縮小范圍)
3、恢復刪除且已提交的數(shù)據(jù)
flashback table 表名 to timestamp to_timestamp('2013-05-29 15:29:00','yyyy-mm-dd hh24:mi:ss');
注意:如果在執(zhí)行上面的語句,出現(xiàn)錯誤。可以嘗試執(zhí)行 alter table 表名 enable row movement; //允許更改時間戳。