FLASHBACK TABLE
[ schema. ]table
[, [ schema. ]table ]...
TO { { SCN | TIMESTAMP } expr
[ { ENABLE | DISABLE } TRIGGERS ]
| BEFORE DROP [ RENAME TO table ]
} ; |
-- 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> |