恢復oracle中update或delete的資料

2021-12-29 23:27:43 字數 2596 閱讀 5103

問題描述

比如在開發人員對employee表進行乙個update語句,但更新完之後,才發現更新的語句有誤,需要撤銷剛才的update操作。如(update employee e set e.block='0300100011000000248' wheree.block='0300100011000000240'; 更新了10條資料)

1、如果在很短的時間內,可以查詢資料庫中的versions,記錄短時間內的employee表中的update、delete、insert的操作。(時間多長取決於資料庫中的相關設定引數)

select versions_xid, versions_operation, versions_starttime, versions_endtime from employee versions between timestamp minvalue and maxvalue;2、如果順利,可以查到剛才update的語句,查出對應的versions_xid的值,然後查詢flashback_transaction_query閃回事務查詢表。

如versions_xid的值為'000a0019000214c3'

select * from flashback_transaction_query where xid ='000a0019000214c3'如果想要取消剛才的update操作,在資料庫中執行查詢出來中的undo_sql欄位中的sql語句即可

時間條件的查詢,如下:

select * from flashback_transaction_query where table_name like 'emp%'

where commit_timestamp< to_date ('2009-2-16 10:30:00','yyyy-mm-dd hh24:mi:ss')

3、如果上面的第2部沒有查詢出來,可以先檢視目前的employee表的資料量是多少,以便和沒有update之前的對比一下

select count(*) from employee

4、可以新生產乙個表來備份update之前的閃回的資料(這也取決於資料庫的閃回時間、undo的大小)

create table employee_copy

asselect * from employee as of timestamp to_timestamp('2009-02-16 10:00:00','yyyy-mm-dd hh24:mi:ss')5、檢視在update之前的employee表 在update語句中的條件是否一樣(比如原來更新語句中的條件是e.block='0300100011000000240',更新了10條),現在查出來也是10條資料,可以把下面10條資料的id查詢出來,然後在更新回去。

select * from employee_copy e where e.block='0300100011000000240';

6、查詢出來employee的id

select count(*) from employee where report_id in ( '8a8881a71c9e53f5011ca74049d7001b', '5f3ba0ea14890024e0437f0000010024', '5a6f193a11a820d8e0430a08012120d8', '56f9dfc764e0101ae0430a3e3d64101a', '8a8881a71cd6ea28011cdf6c372d00a3', '8a8881a71df71207011dfc3071730276', '8a8881a71df71207011dfc38012b0277', '8a8881a71df71207011dfc3f2e50027b', '8a8881a71df71207011dfc0d5ef9022b', '5da7e2d9fa2af06ae0430a080121f06a')7、更新回來原來的資料

update employee set block='0300100011000000240' where report_id in

( '8a8881a71c9e53f5011ca74049d7001b',

'5f3ba0ea14890024e0437f0000010024',

'5a6f193a11a820d8e0430a08012120d8',

'56f9dfc764e0101ae0430a3e3d64101a',

'8a8881a71cd6ea28011cdf6c372d00a3',

'8a8881a71df71207011dfc3071730276',

'8a8881a71df71207011dfc38012b0277',

'8a8881a71df71207011dfc3f2e50027b',

'8a8881a71df71207011dfc0d5ef9022b',

'5da7e2d9fa2af06ae0430a080121f06a')這樣就相當於把原來進行的誤操作sql語句撤銷了。

8、最後把備份的表刪除掉

drop table employee_copy

oracle使用update後閃回恢復資料

使用update後忘記加條件導致全表更新可以使用,閃回技術恢復資料。閃回技術 oracle提供了四種可供使用的閃回技術 閃回查詢,閃回刪除,閃回歸檔,閃回資料庫 一 閃回查詢 1.查詢某個操作是幾時執行的時間點 例查詢2020 11 11執行的update語句 select t.sql text,t...

oracle中update多行資料

a表aid,aname b表bid,bname 現在假設兩張表裡面的資料行數是相等的,現在要更新a表裡面的每一行的anmae,條件是依據b表裡面的bid 在sql server中好像可以這麼寫 update a set aname b.bname from a a,b b where a.aid b...

update之後的資料恢復

本小白日常oracle學習總結,若有錯誤望海涵,並希望大神能指點迷津 用於使用update語句提交之後,恢復使用 1 select r.first load time,r.from v sqlarea r where sql text like update caozyxx 查詢執行誤操作的時間,找...