日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

oracle?delete誤刪除表數據后如何恢復_oracle

作者:weisian151 ? 更新時間: 2022-08-20 編程語言

1、根據時間進行恢復

此種方式需要我們大致知道執行delete語句的時間。

查詢系統當前時間:select to_char(sysdate,‘yyyy-mm-dd hh24:mi:ss’) from dual;

假設在2022-04-02 16:27:11分鐘,執行了刪除語句
delete from demo ;

此時已經表中不能查詢到數據了。我們知道delete執行的時間,往前推1分鐘(delete執行時間之前都可以,越小越好,本例以1分鐘為例),執行如下語句

select * from DEMO as of timestamp to_timestamp(‘2022-04-02 16:26:11',‘yyyy-mm-dd hh24:mi:ss');

可以看到雖然當前demo表中沒有數據,但是可以查詢到demo表前1分鐘時候的數據。

恢復1:此時可以通過plsql工具的導出查詢結果功能導出sql文件,然后在重新執行sql文件中的insert語句進行數據恢復。

恢復2:執行以下sql進行數據恢復:

flashback table DEMO to timestamp to_timestamp(‘2022-04-02 16:26:11',‘yyyy-mm-dd hh24:mi:ss');

如果報錯ORA-08189:未啟用行移動功能,不能閃回表

則執行:

alter table DEMO enable row movement;

添加表行移動功能后,在進行flashback語句進行恢復

如果報錯: ORA-08194: 在實體化視圖上不允許閃回表操作;則通過下面介紹的新建臨時表的方式進行恢復。

恢復3(新建臨時表):

新建demo1表,插入需要恢復的數據

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表的數據恢復到demo表中

insert into DEMO select * from DEMO1 where not exists (select * from DEMO where DEMO.id=DEMO1.id);

恢復4(根據scn恢復):

查詢當前的scn號

select current_scn from v$database;

將scn號減少若干,執行下語句,直到能查看到我們delete的數據為止

select * from DEMO as of scn 166937913;

通過合適的scn號,執行下sql語句進行數據恢復

flashback table DEMO to scn 166937913;

總結

原文鏈接:https://blog.csdn.net/qq_34207422/article/details/123924927

欄目分類
最近更新