Oracle FlashBack ---- 2016-05-04

Oracle FlashBack功能的应用

在日常的工作中,我们有时会不小心删掉了某些并不想删掉的数据。这个时候就可以通过flashback来恢复数据。楼主对其原理并不了解,这里只包含一些简单的应用。

1. 直接将某个table回复到某个时间点。

delete from Table ~~;

select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;

alter table Table~~ enable row movement;

flashback table Table~~ to timestamp to_timestamp('2016-02-20 14:31:43','yyyy-mm-dd hh24:mi:ss');

 2. 如果在删除数据之后有一些新的记录插入到了表中,这时直接恢复就会删除后面的数据。可以采用下面的方式来恢复。

insert into Table ~~
select * from Table ~~
as of timestamp to_timestamp('2016-02-20 11:45:13','YYYY-MM-DD HH24:MI:SS');

在上面的sql中也可以比较现在和过去某一个时间点表中数据的差异,来把重复的数据排除在外。

insert into Table~~(select * from  Table~~as of timestamp to_timestamp('2016-05-03 14:24:29','yyyy-mm-dd hh24:mi:ss') 
where some_Column not in (select some_Column  from Table~~ ));

猜你喜欢

转载自simon-9527.iteye.com/blog/2295878