delete误删数据,恢复方法

转自http://blog.itpub.net/20976446/viewspace-716109

与作者情况类似,转过来做下标记。

由于开发人员在早晨大概在9点左右不小心删除了某张表的一些数据(delete from logmessage where where taskid='6471';),目前急需恢复删除的数据,恢复步骤如下
第一:首先通过大概时间点来查询SCN(将删除时间转换为scn)
SQL> select timestamp_to_scn(to_timestamp('2012-02-13 09:00:00','YYYY-MM-DD HH:MI:SS')) from dual;

TIMESTAMP_TO_SCN(TO_TIMESTAMP(
------------------------------
                      16360271
第二:通过SCN查询被删除的数据(将logmessage表中的scn点的数据取出,然后可以根据这个数据进行还原操作)
SQL> select * from logmessage as of scn 16360271 where taskid='6471';
数据省略写下
10542   6471 20110314_中国_3网测试_市区测试与评估_市区mos及do上传_0314-142146-2.loc           2012-2-10 1 电信CDMA      语音    自动路测     市区    2                    

1 rows selected
第三:确认查询被删除后表中总的有多少数据
SQL> select count(*) from logmessage;

  COUNT(*)
----------
      2515
SQL> select * from logmessage where where taskid='6471';这个查询到并没有taskid='6471'的值在logmessage表中
第四:通过SCN的值来恢复被删除的数据(taskid='6471')
SQL> insert into logmessage  select * from logmessage as of scn 16360271 where taskid='6471';

8 rows inserted
SQL> commit;

Commit complete

第五:确认被恢复的数据
SQL> select count(*) from logmessage;

  COUNT(*)
----------
      2523

猜你喜欢

转载自wsfeiyuan.iteye.com/blog/2087487