对误删的表记录,只要没有truncate语句,就可以根据事务的提交时间进行选择恢复,一般步骤有:
1、先从flashback_transaction_query视图里查询,视图提供了供查询用的表名称、事务提交时间、UNDO_SQL等字段。注意:11g查看到UNDO_SQL为空,是因为
Oracle11g禁用了supplemental logging
开启后恢复正常:
alter database add supplemental log data;
SQL> alter database add supplemental log data;
如:select * from flashback_transaction_query where table_name='TEST';
select START_SCN,START_TIMESTAMP,COMMIT_SCN,COMMIT_TIMESTAMP,UNDO_CHANGE#,TABLE_NAME,TABLE_OWNER,UNDO_SQL from flashback_transaction_query where table_name='EMP2' order by COMMIT_TIMESTAMP desc
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');
select * from emp2 as of scn 699992;-------这个是COMMIT_SCN的值
若有数据,恢复极为简单了,语句为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');
flashback table emp2 to scn 699992;
如果是误update,而且提交。(update emp2 set comm=700 where deptno=10),闪回时,执行上一个时间段的时间或者scn。我这里是703623,703654是查到update提交后的值
select * from emp2 as of scn 703623;-------这个是COMMIT_SCN的值
flashback table emp2 to scn 699992;
无删除
delete from emp2 where deptno=30; 闪回到改sql语句COMMIT_SCN的值,才是正确的。和update有区别。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29893219/viewspace-1851421/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29893219/viewspace-1851421/