ORACLE数据表回闪技术使用
2018-12-05 本文已影响0人
许俊贤
oracle数据表回闪技术使用
明确到自己要查询的时间点
select gather_id from tb_budget_audit as of timestamp to_timestamp('2018-01-5 16:30:16','YYYY-MM-DD hh24:mi:ss') where id =39865213;
标识红色的为自己查询的某个时间点,但因为数据库做更新操作的时间点属于毫秒级别,这时候时间点已经没有办法满足需求了
这时候需要SCN来明确区间断了,已经远远比毫秒还要精确(SCN相当于数据库的时间点记录)
首先将自己要查询的时间端转换于SCN的区间段。
eg:
select timestamp_to_scn(to_timestamp('2018-01-5 16:49:15','YYYY-MM-DD hh24:mi:ss:')) from dual;
select timestamp_to_scn(to_timestamp('2018-01-5 16:49:16','YYYY-MM-DD hh24:mi:ss')) from dual;
这是1秒之差的scn变化查询之后在通过遍历输出语句查询。
上述获取两个值的差值作轮询。
select gather_id from tb_budget_audit as of scn 5152329793 where id =39865213;
数据表闪回到某个时间点执行步骤:
查询最近更新数据之前的数据(以便确定是不是Commit之前的数据)
select * from account as of timestamp to_timestamp('2018-01-22 08:00:00', 'yyyy-mm-dd hh24:mi:ss');
其中account为被误操作的表,'2018-01-22 08:00:00'表示上次更新数据前的时间,
闪回操作前启用行移动功能(不启用不可以闪回)
alter table account enable row movement;
其中account表示被误操作的表
执行闪回语句:
flashback table account to timestamp TO_TIMESTAMP('20140422 15:10:00','YYYYMMDD HH24:MI:SS');
这样被误操作的数据就可以恢复了。
备注:个人博客同步至简书。