导航

Oracle误删表的恢复

Posted on 2012-02-23 10:11  C'est la vie  阅读(1282)  评论(0编辑  收藏  举报

利用ORACLE闪回机制,将删除的表闪回回来

找到回收站里删掉的表

select * from user_recyclebin where DROPTIME >'2012-02-22 00:00:00'; 

 

在闪之前, 但删除的表,如果又重新创建了一样的表名,所以不能直接闪回,要先删除这些表, (如需删除冲突表,执行此以下查询结果内容中的sql语句) 

select 'drop table '||ORIGINAL_NAME||' cascade constraint;' from user_recyclebin where DROPTIME >'2010-02-08 09:00:00' and type = 'TABLE'; 

 

( 生成闪回表的语句  )

select 'flashback table '||ORIGINAL_NAME||' to before drop;' from user_recyclebin where DROPTIME >'2012-02-22 17:00:00' and type = 'TABLE'; 


(索引恢复)

select 'ALTER INDEX "'||OBJECT_NAME||'" rename to '||ORIGINAL_NAME||';'  from user_recyclebin where DROPTIME >'2012-02-22 17:00:00' and type = 'INDEX';


(触发器恢复)

select 'ALTER TRIGGER "'||OBJECT_NAME||'" rename to '||ORIGINAL_NAME||';'  from user_recyclebin where DROPTIME >'2012-02-22 17:00:00' and type = 'TRIGGER';