免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 846 | 回复: 0
打印 上一主题 下一主题

ORACLE FLASHBACK [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-19 13:56 |只看该作者 |倒序浏览
oracle的flashback
1、flashback query
2、flashback drop
3、flashback version query
4、flashback transaction query
5、flashback table
6、flashback database
 
1、FLASHBACK QUERY
适用环境:查询过去某个时点的表的情况; 
 用法:
select * from table_name as of timestamp()
--闪回到15分钟前
 select *  from orders   as of timestamp (systimestamp - interval '15' minute)   where ......
 这里可以使用DAY、SECOND、MONTH替换minute,例如:
 SELECT * FROM orders AS OF TIMESTAMP(SYSTIMESTAMP - INTERVAL '2' DAY)
 --闪回到某个时间点
 select  *   from orders   as of timestamp   to_timestamp ('01-Sep-04 16:18:57.845993', 'DD-Mon-RR HH24:MI:SS.FF') where ...
  --闪回到两天前
 select * from orders   as of timestamp (sysdate - 2) where.........
 
2、FLASHBACK DROP
适用环境:误删除了某张表。相关视图recylebin;
用法: flashback table table_name to before drop [rename to table_name2]
 
3、FLASHBACK VERSION QUERY
适用环境:查找表的更改历程,即在某一段时间内的每次更改的情况
用法: 
 1)select * from table_name
          versions between SCN
               minvalue and maxvalue
   where ...
 2)select * from table_name
         versions between timestamp
           to_timestamp('2010-01-01 12:15:10','YYYY-MM-DD HH:MI:SS') and
           to_timestamp('2010-01-01 13:20:10','YYYY-MM-DD HH:MI:SS') and
   where ...
 
注:此处有几个隐含虚拟列:
   versions_starttime
   versions_endtime
   versions_startscn
   versions_endscn
   versions_xid   --版本元数据的唯一标识
   versions_operation  ----i: insert d:delete u:update
  还有一个新的函数:scn_to_timestamp
  如:select current_scn,scn_to_timestamp(current_scn) from v$database;
 
4、FLASHBACK TRANSCATION QUERY:
适用环境:查找表的更改的transcation语句
用法: 
1)select * from flashback_transcation_query
where XID='' -----此处的XID 通过 3中的VERSION_XID来得到
2)select * from flashback_transcation_query
where start_timestamp>=to_timestamp('2011-01-15 10:15:20','yyyy-mm-dd hh:mi:ss')
and table_name='XXXX'
 
5、FLASHBACK TABLE:
适用环境:误使用了where条件后的操作;
用法:
 1)alter table table_name enable row movement;
 2)flashback table table_name to scan xxxx
 or
 2)flashback table table_name to timestamp
   如:闪回表到15分钟前:
   flashback table order   to timestamp systimestamp - interval '15' minute;
     闪回到某个时间点:
   FLASHBACK TABLE order TO TIMESTAMP    TO_TIMESTAMP('2007-09-12 01:15:25 PM','YYYY-MM-DD HH:MI:SS AM)
 
  
  
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP