Oracle 10g以後的版本中引入了"資源回收筒"(Recycle Bin)的概念,刪除的對象統一清除,以BIN$最為首碼命名.使用者刪除某個表,可以很容易的從"資源回收筒"中還原回來,但在9i以前是對於刪除表這樣的DDL操縱是不能直接還原回來的,通常需要做不完全恢複或是使用EXP/IMP來恢複. 1.查看當前資源回收筒功能是否開啟(預設情況下是開啟的)
SQL> column value format a10;
SQL> select value from V$parameter where name = 'recyclebin';VALUE
----------
on
可以使用如下命令開啟或關閉該功能.sql> alter system set recyclebin = on scope=spfile;
or
sql> alter session set recyclebin = on scope=spfile;sql> alter system set recyclebin = off scope=spfile;
or
sql> alter session set recyclebin = off scope=spfile;
2.查看資源回收筒裡的內容
SQL> show recyclebin;
or
SQL> select * from user_recyclebin;
下面將建立的表刪除後清除
SQL> show user;
USER is "HXL"
SQL> create table test_rbin(val number);
Table created.
SQL> insert into test_rbin(val) values(10);
1 row created.
SQL> commit;
Commit complete.
SQL> drop table test_rbin;
Table dropped.
SQL> show recyclebin;
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST_RBIN BIN$S4u3UNw0QQ6t6LRxMMz7hQ==$0 TABLE 2012-06-22:15:01:30
3.從資源回收筒恢複刪除的表
可以使用如下語句從資源回收筒恢複刪除的表
sql > flashback table <<table_name>> to before drop;
例如我們恢複剛才刪除的表
SQL> flashback table test_rbin to before drop;
Flashback complete.
SQL> select * from test_rbin;
VAL
----------
10
在恢複的過程的同時我們可以將表另外命名,命令如下:
sql>flashback table << dropped table name >> to before drop rename to <<new table name >>;
sql>flashback table test_rbin to before drop rename to test_rbin1;
Oracle從資源回收筒恢複是按照"降序"恢複的,比如連續3次刪除同樣一個表(刪除後再建立,再刪除),恢複的是先恢複最後一次刪除的表.
SQL> show user;
USER is "HXL"
SQL> drop table test_rbin;
Table dropped.
SQL> create table test_rbin (col1 number);
Table created.
SQL> insert into test_rbin values (1);
1 row created.
SQL> commit;
Commit complete.
SQL> drop table test_rbin;
Table dropped.
SQL> create table test_rbin (col1 number);
Table created.
SQL> insert into test_rbin values (2);
1 row created.
SQL> commit;
Commit complete.
SQL> drop table test_rbin;
Table dropped.
SQL> create table test_rbin (col1 number);
Table created.
SQL> insert into test_rbin values (3);
1 row created.
SQL> commit;
Commit complete.
SQL> drop table test_rbin;
Table dropped.
SQL> show recyclebin;
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST_RBIN BIN$gGHkV/xQSSaQ5bG0PikSAg==$0 TABLE 2012-06-22:15:31:21
TEST_RBIN BIN$xVKygKwJTJa+8zmu4BJzvQ==$0 TABLE 2012-06-22:15:30:53
TEST_RBIN BIN$R7As9PsYRva7CY6cnAjROw==$0 TABLE 2012-06-22:15:30:23
TEST_RBIN BIN$0R+cRKhDTFu+8ShBjLDpqg==$0 TABLE 2012-06-22:15:29:27
SQL> select * from test_rbin1;
COL1
----------
3
SQL> select * from test_rbin2;
COL1
----------
2
SQL> select * from test_rbin3;
COL1
----------
1