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)
阅读(1164) | 评论(0) | 转发(0) |