ITPub博客

首页 > 数据库 > Oracle > 闪回技术一:闪回查询

闪回技术一:闪回查询

原创 Oracle 作者:sky850623 时间:2014-07-05 19:47:13 0 删除 编辑
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博客 ” ,链接:https://blog.itpub.net/26937943/viewspace-1210453/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: purge表
请登录后发表评论 登录
全部评论

注册时间:2013-05-30

  • 博文量
    154
  • 访问量
    515705