zoukankan      html  css  js  c++  java
  • 【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

  • 相关阅读:
    java多线程--线程和线程池
    java多线程--锁学习
    vue项目中使用iconfont
    组件封装-无数据组件
    添加自定义字体
    时间格式化(自定义格式)
    深度克隆方法
    LazyMan面试题
    lodash.throttle实现节流
    第6章:关系数据库理论(考研重点)
  • 原文地址:https://www.cnblogs.com/NextAction/p/7366656.html
Copyright © 2011-2022 走看看