SQL——flashback table语法

1. 语法
 
FLASHBACK TABLE
   [ schema. ]table
     [, [ schema. ]table ]...
   TO { { SCN | TIMESTAMP } expr
        [ { ENABLE | DISABLE } TRIGGERS ]
      | BEFORE DROP [ RENAME TO table ]
      } ;

 

2. 测试当回收站中存在两个重名的表时,如何闪回:
-- 1. 创建测试环境
C:/Documents and Settings/yuechao.tianyc>sqlplus test/test
 
SQL*Plus: Release 10.2.0.1.0 - Production on 星期二 3月 31 18:52:38 2009
 
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
 
 
连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
 
SQL> create table test_purge as select 1 a from dual;
 
表已创建。
 
SQL> drop table test_purge;
 
表已删除。
 
SQL> show recyclebin
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST_PURGE       BIN$op097VdeQwKNHTBVCa/23w==$0 TABLE        2009-03-31:19:04:10
 
SQL> create table test_purge as select 1 a, 2 b from dual;
 
表已创建。
 
SQL> drop table test_purge;
 
表已删除。
 
 
SQL> show recyclebin
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST_PURGE       BIN$fvirzrOASPCDF5v1WSe9iw==$0 TABLE        2009-03-31:19:04:33
TEST_PURGE       BIN$op097VdeQwKNHTBVCa/23w==$0 TABLE        2009-03-31:19:04:10
 
-- 2. 闪回:此时采用“后进先出”的策略来闪回
SQL> flashback table test_purge to before drop;
 
闪回完成。
 
SQL> desc test_purge
 名称                                      是否为空? 类型
 ----------------------------------------- -------- ----------------------------
 A                                                  NUMBER
 B                                                  NUMBER
 
SQL> show recyclebin
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST_PURGE       BIN$op097VdeQwKNHTBVCa/23w==$0 TABLE        2009-03-31:19:04:10
 
-- 3. 继续闪回:因为名称相同而失败
SQL> flashback table test_purge to before drop;
flashback table test_purge to before drop
*
第 1 行出现错误:
ORA-38312: 原始名称已被现有对象使用
 
 
-- 3. 使用rename to 子句来闪回第二个同名的表
SQL> flashback table test_purge to before drop rename to test_purge_old;
 
闪回完成。
 
SQL> desc test_purge_old
 名称                                      是否为空? 类型
 ----------------------------------------- -------- ---------------------------
 A                                                  NUMBER
 
SQL> show recyclebin
SQL>
 
-- 4. 测试 purge table:按照“先进先出”的顺序purge
SQL> drop table test_purge;
 
表已删除。
 
SQL> show recyclebin
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST_PURGE       BIN$ei/ce6WZTPiZ5CBiAbBRXQ==$0 TABLE        2009-03-31:20:43:03
 
SQL> rename test_purge_old to test_purge;
 
表已重命名。
 
SQL> drop table test_purge;
 
表已删除。
 
SQL> show recyclebin
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST_PURGE       BIN$SiNTtrq9TduKnIPxRynwbQ==$0 TABLE        2009-03-31:20:43:43
TEST_PURGE       BIN$ei/ce6WZTPiZ5CBiAbBRXQ==$0 TABLE        2009-03-31:20:43:03
 
SQL> purge table test_purge;
 
表已清除。
 
SQL> show recyclebin
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST_PURGE       BIN$SiNTtrq9TduKnIPxRynwbQ==$0 TABLE        2009-03-31:20:43:43
 
SQL> purge table test_purge;
 
表已清除。
 
SQL>  show recyclebin
SQL>

该博文摘自http://blog.chinaunix.net/u/30637/showart_1886656.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值