ITPub博客

首页 > 数据库 > Oracle > oracle闪回查询

oracle闪回查询

原创 Oracle 作者:chenoracle 时间:2014-10-14 15:41:33 0 删除 编辑

SQL> select * from t1 as of timestamp (systimestamp - interval '2' minute);   ---查询t1表2分钟之前的数据
SQL> select * from t1 as of timestamp (systimestamp - interval '120' second); ---查询t1表120秒之前的数据
SQL> select * from dept as of timestamp (systimestamp - interval '12' hour);  ---查询dept表12小时之前的数据
SQL> select * from dept as of timestamp (systimestamp - interval '12' day);   ---查询dept表12天之前的数据
SQL> select * from cardacct as of timestamp sysdate-2;                              ---查询cardacct表2天之前的数据
SQL> select timestamp_to_scn(to_timestamp('2014-08-24 05:15:22','yyyy-mm-dd hh24:mi:ss')) scn from dual;       --时间和scn之间的转换
       SCN
----------
   1081597

SQL> select scn_to_timestamp(1081597) scn from dual;
SCN
---------------------------------------------------------------------------
24-AUG-14 05.15.21.000000000 AM


闪回查询表t1
SQL> select * from t1;
no rows selected

SQL> select * from t1 as of timestamp (systimestamp - interval '2' minute);

    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON


SQL> flashback table t1 to timestamp (systimestamp - interval '2' minute);
Flashback complete.


SQL> select * from t1;
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON


SQL> select * from t1 as of timestamp (systimestamp - interval '120' second);
    DEPTNO DNAME          LOC
---------- -------------- -------------
        10 ACCOUNTING     NEW YORK
        20 RESEARCH       DALLAS
        30 SALES          CHICAGO
        40 OPERATIONS     BOSTON


欢迎关注我的微信公众号"IT小Chen",共同学习,共同成长!!!



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

下一篇: oracle dblink
请登录后发表评论 登录
全部评论
Oracle ACE、OCMU 用户组成员、Oracle 11g OCM、微信公众号"IT小Chen"

注册时间:2014-08-05

  • 博文量
    853
  • 访问量
    2727926