Oracle 資料庫中 drop table 與purge

來源:互聯網
上載者:User

實際樣本:

CREATE OR REPLACE PROCEDURE pro_droptable IS

  cursor cur is

    select table_name from user_tables where table_name like 'TEMPTABLE%';

  drop_sql     varchar2(1000);

  table_number number;

BEGIN

  SELECT COUNT(*) INTO table_number from USER_TABLES WHERE TABLE_NAME LIKE 'TEM%';

  for tbname in cur loop

    begin

      if table_number < 50 then

        exit;

      end if;

      drop_sql := 'drop table ' || tbname.table_name || 'purge';

      execute immediate drop_sql;

      table_number := table_number - 1;

  

    end;

  end loop;

END pro_droptable;

解釋:

drop後的表被放在資源回收筒(user_recyclebin)裡,而不是直接刪除掉。這樣,資源回收筒裡的表資訊就可以被恢複,或徹底清除。
1.通過查詢資源回收筒user_recyclebin擷取被刪除的表資訊,然後使用語句
flashback table <user_recyclebin.object_name or user_recyclebin.original_name> to before drop [rename to <new_table_name>];
將資源回收筒裡的表恢複為原名稱或指定新名稱,表中資料不會丟失。
若要徹底刪除表,則使用語句:drop table <table_name> purge;
2.清除資源回收筒裡的資訊
清除指定表:purge table <table_name>;
清除目前使用者的資源回收筒:purge recyclebin;
清除所有使用者的資源回收筒:purge dba_recyclebin;


樣本2:

CREATE OR REPLACE PROCEDURE pro_clean_recycle IS

--tmpVar NUMBER;

clean_recycle_sql varchar2(1000);

BEGIN

   --purge recyclebin;

   clean_recycle_sql :='purge recyclebin';

   execute immediate clean_recycle_sql;

END pro_clean_recycle;

更多Oracle相關資訊見Oracle 專題頁面 http://www.bkjia.com/topicnews.aspx?tid=12

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.