實際樣本:
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