• 【Oracle】闪回表


    语法:

    FLASHBACK TABLE [ schema. ] table [, [ schema. ] table ]...

    TO { { { SCN | TIMESTAMP } expr| RESTORE POINT restore_point}

    [ { ENABLE | DISABLE } TRIGGERS ]| BEFORE DROP [ RENAME TO table ]} ;

    注  flashback table  为 ddl

     

    1.创建测试表T1,并插入数据

    SCOTT@lgr> create table t1 (x number(2),d date);

     

    Table created.

     

    SCOTT@lgr> insert into t1 (x) values(1);

     

    1 row created.

     

    SCOTT@lgr> insert into t1 values(2,sysdate);

     

    1 row created.

     

    SCOTT@lgr> commit;

     

    Commit complete.

     

    SCOTT@lgr> select * from t1;

     

             X D

    ---------- -------------------

             1

             2 2017-02-19,10:53:41

     

    2.记录当前的时间

    SCOTT@lgr> select sysdate from dual;

     

    SYSDATE

    -------------------

    2017-02-19,10:54:49

     

    3.删除T1表中的一条数据

    SCOTT@lgr> delete t1 where x=2;

     

    1 row deleted.

     

    SCOTT@lgr> commit;

     

    Commit complete.

     

    SCOTT@lgr> select * from t1;

     

             X D

    ---------- -------------------

             1

     

    4.此时对表进行闪回,会出现错误。原因很明显,因为表T1没有开启行移动

    SCOTT@lgr> flashback table t1 to timestamp to_date('2017-02-19,10:54:49','yyyy-mm-dd,hh24:mi:ss');

    flashback table t1 to timestamp to_date('2017-02-19,10:54:49','yyyy-mm-dd,hh24:mi:ss')

                    *

    ERROR at line 1:

    ORA-08189: cannot flashback the table because row movement is not enabled

     

    SCOTT@lgr> select table_name,row_movement from user_tables where table_name='T1';

     

    TABLE_NAME                     ROW_MOVE

    ------------------------------ --------

    T1                             DISABLED

     

    5.对表T1开启行移动

    SCOTT@lgr> alter table t1 enable row movement;

     

    Table altered.

     

    6.对表T1进行基于时间点的闪回操作

    SCOTT@lgr> flashback table t1 to timestamp to_date('2017-02-19,10:54:49','yyyy-mm-dd,hh24:mi:ss');

     

    Flashback complete.

     

    SCOTT@lgr> select * from t1;

     

             X D

    ---------- -------------------

             1

             2 2017-02-19,10:53:41

  • 相关阅读:
    day 08 小结
    day 07作业
    逆向---入坑记
    Codeforces Round #523 (Div. 2) B,D
    VIM一键配置
    zoj 2704 Brackets 用栈维护括号匹配 (8-A)
    zoj 2840 File Searching
    zoj 1698 Easier Done Than Said?
    13暑假集训6 总结
    13暑假集训#7 总结
  • 原文地址:https://www.cnblogs.com/NextAction/p/7366656.html
Copyright © 2020-2023  润新知