oracle闪回使用以及删除存储过程恢复

oracle恢复删除的数据

 恢复删除的存储过程
SELECT * FROM dba_source as of timestamp (systimestamp -interval'600'second)

分为两种方法:scn和时间戳两种方法恢复。

一、通过scn恢复删除且已提交的数据

  1、获得当前数据库的scn号

    select current_scn from v$database; (切换到sys用户或system用户查询) 

    查询到的scn号为:1499223

  2、查询当前scn号之前的scn

    select * from 表名 as of scn 1499220; (确定删除的数据是否存在,如果存在,则恢复数据;如果不是,则继续缩小scn号)

  3、恢复删除且已提交的数据

    flashback table 表名 to scn 1499220;

二、通过时间恢复删除且已提交的数据

  1、查询当前系统时间

    select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;

  2、查询删除数据的时间点的数据

    select * from 表名 as of timestamp to_timestamp('2013-05-29 15:29:00','yyyy-mm-dd hh24:mi:ss');  (如果不是,则继续缩小范围)

  3、恢复删除且已提交的数据

    flashback table 表名 to timestamp to_timestamp('2013-05-29 15:29:00','yyyy-mm-dd hh24:mi:ss');

    注意:如果在执行上面的语句,出现错误。可以尝试执行 alter table 表名 enable row movement; //允许更改时间戳

 

 

一:表的恢复
     对误删的表,只要没有使用PURGE永久删除选项,那么从flash back区恢复回来希望是挺大的。一般步骤有:
1、从flash back里查询被删除的表
    select * from recyclebin
2.执行表的恢复
   flashback table  tb  to before drop,这里的tb代表你要恢复的表的名称。
二:表数据恢复
    对误删的表记录,只要没有truncate语句,就可以根据事务的提交时间进行选择恢复,一般步骤有:
     1、先从flashback_transaction_query视图里查询,视图提供了供查询用的表名称、事务提交时间、UNDO_SQL等字段。
     如:select * from flashback_transaction_query where table_name='TEST';
     2、执行表记录恢复
     一般先根据时间进行查询,查询语句模式为select * from tb as of timestamp to_timestamp(time,'yyyy-mm-dd hh24:mi:ss'); tb指表名称,time指某个时间点
      如select * from scott.test as of timestamp to_timestamp('2009-12-11 20:53:57','yyyy-mm-dd hh24:mi:ss');
    若有数据,恢复极为简单了,语句为flashback table tb to timestamp to_timestamp(time,'yyyy-mm-dd hh24:mi:ss');
   如flashback table scott.test to timestamp to_timestamp('2009-12-11 20:47:30','yyyy-mm-dd hh24:mi:ss');
 
注意:alter table testvarchar enable row movement;

posted on 2015-11-04 11:17  anruy  阅读(5601)  评论(0编辑  收藏  举报

导航