闪回技术一:闪回查询

1.创建一表并插入数据
SQL> create table t (x int,name varchar2(10));
表已创建。
SQL> insert into t values(1,'a');
已创建 1 行。
SQL> insert into t values(2,'b');
已创建 1 行。
SQL> insert into t values(3,'b');
已创建 1 行。
SQL> insert into t values(4,'d');
已创建 1 行。
SQL> commit;
提交完成。
SQL> select * from t;
         X NAME
---------- ----------
         1 a
         2 b
         3 b
         4 d
2.查询当前SCN
SQL> select current_scn from v$database;
CURRENT_SCN
-----------
     967014
3.删除一行
SQL> delete from t where x=4;
已删除 1 行。
SQL> commit;
提交完成。
SQL> select * from t;
         X NAME
---------- ----------
         1 a
         2 b
         3 b
4.闪回查询
SQL> select * from t as of scn 967014;
         X NAME
---------- ----------
         1 a
         2 b
         3 b
         4 d
把scn转成时间
SQL> select scn_to_timestamp(967014) from dual;
SCN_TO_TIMESTAMP(967014)
--------------------------------------------------
05-7月 -14 07.41.13.000000000 下午
按时间闪回查询
SQL> select * from t as of timestamp to_date('2014-7-5 19:41:00','yyyy-mm-dd hh24:mi:ss');
         X NAME
---------- ----------
         1 a
         2 b
         3 b
         4 d
5.恢复数据
SQL> insert into t select * from t as of timestamp to_date('2014-7-5 19:41:00','yyyy-mm-dd hh24:mi:ss') where x=4;
已创建 1 行。
SQL> commit;
提交完成。
SQL> select * from t;
         X NAME
---------- ----------
         1 a
         2 b
         3 b
         4 d



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26937943/viewspace-1210453/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26937943/viewspace-1210453/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值