Flashback Query它可以穿越到过去查看过去的能力,不具有恢复数据的能力。
但是既然可以select出来过去的数据,当然可以执行insert table select 来恢复数据了。
1、基于时间的查询,恢复数据。局限性:对于过个互相有主外键约束的表恢复,可能会由于时间点不统一导致数据选择或插入失败
假如误删数据:delete table_name where ID<10; commit。当前距离删除操作有5分钟左右的时间。
我们要做的是: select * from table_name as of timestamp sysdate-5/1440
insert into table_name select * from table_name as of timestamp sysdate-5/1440 where ID<10;
2、基于SCN查询,恢复数据。
查询当前scn方式: 通过查询V$DATABASE视图中的currrent_scn列获取,或者使用DBMS_FLASHBACK.GRT_SYSTEM_CHANGE_NUMBER函数。
这两种方式都要求操作的用户必须拥有要操作对象的访问权限。
grant execute on dbms_flashback on scott; 或者 grant select on V_$DATABAS to scott;
误删与恢复过程是:
select DBMS_FLASHBACK.GET_SYSTEM_CHANGE_NUMBER from dual; 获得scn:123
然后delete table_name where ID>10; commit。
insert into table_name select * from table_name as of scn 123 where id>10;