oracle恢复被删除的数据

两种方法:(1)、scn方法   (2)、时间戳法

(1)、scn方法(通过scn恢复删除数据的sql语法)

  a、获取当前数据库的scn号

    select  current_scn  from  v$database;

    查询到的scn号为:  

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

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

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

    flashback  table  表名  to  scn   scn号

 (2)、时间戳方法

  a、查询当前系统的时间  

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

  b、select  *  from  表名   as  of  timestamp  to_timestamp('2020-02-02 15:22:00', 'yyyy-mm-dd  hh24:mi:ss')(如果不是继续缩小范围)

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

   --开启行移动功能(解决执行一下语句报错的问题)

     alter  table  表名  enable  row   movement;

   --恢复某个时间点的数据

     flashback  table  表名  to  timestamp  to_timestamp ('2020-02-02 15:21:00', 'yyyy-mm-dd hh24:mi:ss');

   --关闭行移动功能

    alter table  表名  disable  row  movement;

----------------------------------------------------------------------------------------------------

--开启行移动功能(解决执行以下语句报错问题)

alter   alter  表名   enable   row  movement;

--恢复某个时间点的数据

flashback  table  表名  to   timestamp to_timestamp ('2020-02-02  12:12:00', 'yyyy-mm-dd  hh24:mi:ss')   (保证此时间为删除操作之前的操作)

--关闭行移动功能

alter  alter  表名  disable  row   movement;

参考:https://www.cnblogs.com/xielong/p/11239939.html

原文地址:https://www.cnblogs.com/wongzzh/p/13435366.html