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