本篇文章給大家?guī)砹岁P(guān)于Oracle的相關(guān)知識(shí),在使用oracle數(shù)據(jù)時(shí),一不小心把table中的數(shù)據(jù)delete掉并且已經(jīng)提交了,下面介紹關(guān)于oracle delete誤刪除表數(shù)據(jù)后如何恢復(fù)的相關(guān)資料,希望對大家有幫助。
推薦教程:《Oracle視頻教程》
根據(jù)時(shí)間進(jìn)行恢復(fù)
此種方式需要我們大致知道執(zhí)行delete語句的時(shí)間。
查詢系統(tǒng)當(dāng)前時(shí)間:select to_char(sysdate,‘yyyy-mm-dd hh24:mi:ss’) from dual;
假設(shè)在2022-04-02 16:27:11分鐘,執(zhí)行了刪除語句delete from demo ;
此時(shí)已經(jīng)表中不能查詢到數(shù)據(jù)了。我們知道delete執(zhí)行的時(shí)間,往前推1分鐘(delete執(zhí)行時(shí)間之前都可以,越小越好,本例以1分鐘為例),執(zhí)行如下語句
select * from DEMO as of timestamp to_timestamp(‘2022-04-02 16:26:11',‘yyyy-mm-dd hh24:mi:ss');
可以看到雖然當(dāng)前demo表中沒有數(shù)據(jù),但是可以查詢到demo表前1分鐘時(shí)候的數(shù)據(jù)。
恢復(fù)1:此時(shí)可以通過plsql工具的導(dǎo)出查詢結(jié)果功能導(dǎo)出sql文件,然后在重新執(zhí)行sql文件中的insert語句進(jìn)行數(shù)據(jù)恢復(fù)。
恢復(fù)2:執(zhí)行以下sql進(jìn)行數(shù)據(jù)恢復(fù):
flashback table DEMO to timestamp to_timestamp(‘2022-04-02 16:26:11',‘yyyy-mm-dd hh24:mi:ss');
如果報(bào)錯(cuò)ORA-08189:未啟用行移動(dòng)功能,不能閃回表
則執(zhí)行:
alter table DEMO enable row movement;
添加表行移動(dòng)功能后,在進(jìn)行flashback語句進(jìn)行恢復(fù)
如果報(bào)錯(cuò): ORA-08194: 在實(shí)體化視圖上不允許閃回表操作;則通過下面介紹的新建臨時(shí)表的方式進(jìn)行恢復(fù)。
恢復(fù)3(新建臨時(shí)表):
新建demo1表,插入需要恢復(fù)的數(shù)據(jù)
create table DEMO1 as select * from DEMO as of timestamp to_timestamp(‘2022-04-02 16:30:11',‘yyyy-mm-dd hh24:mi:ss');
將demo1表的數(shù)據(jù)恢復(fù)到demo表中
insert into DEMO select * from DEMO1 where not exists (select * from DEMO where DEMO.id=DEMO1.id);
恢復(fù)4(根據(jù)scn恢復(fù)):
查詢當(dāng)前的scn號(hào)
select current_scn from v$database;
將scn號(hào)減少若干,執(zhí)行下語句,直到能查看到我們delete的數(shù)據(jù)為止
select * from DEMO as of scn 166937913;
通過合適的scn號(hào),執(zhí)行下sql語句進(jìn)行數(shù)據(jù)恢復(fù)
flashback table DEMO to scn 166937913;
推薦教程:《Oracle視頻教程》