Oracle從“資源回收筒”恢複刪除的表

來源:互聯網
上載者:User

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

  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.