使用PL/SQL快速刪除使用者下的所有表資料

來源:互聯網
上載者:User

在Oracle中如果要刪除使用者的表資料有多種的方法,這裡可推薦一種比較快速的方法,能夠刪除使用者下的所有表資料,通過plsql這個語言就可以快速的刪除,代碼如下所示:

declare
  cursor c_t is (select table_name from user_tables);--聲明一個遊標
  table_name user_tables.table_name%type;--聲明一個表名的變數
begin
  open c_t;
  loop—迴圈
      fetch c_t into table_name;
      exit when c_t%notfound;
      execute immediate 'delete from ' || table_name;--動態sql刪除
  end loop;
  close c_t;
end;

在Oracle中,user_tables是一張字典表,儲存了使用者表的資訊,我們通過遊標可以擷取到該字典表中儲存的目前使用者表的資訊,然後迴圈刪除每一張表裡的資料。很簡單的,這個在開發的過程中應該會經常遇到的。

rlwrap - 解決Linux下SQLPLUS退格、上翻鍵亂碼問題

SQLPLUS spool 到動態記錄檔名

Oracle SQLPLUS提示符設定

通過設定SQLPLUS ARRAYSIZE(行預取)加快SQL返回速度

聯繫我們

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