oracle關于刪除表內容和用戶名使用
檢索用戶名:select user from dual
刪除當前用戶下所有表的內容:
declare
-- 指向所有 table 的游標
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;
-- 用 delete 而不用 truncate 是為了能戶用戶回滾,減少誤操作
execute immediate 'delete from ' || table_name;
end loop;
close c_t;
end;
刪除當前用戶下所有表的內容:
declare
-- 指向所有 table 的游標
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;
-- 用 delete 而不用 truncate 是為了能戶用戶回滾,減少誤操作
execute immediate 'delete from ' || table_name;
end loop;
close c_t;
end;
posted on 2012-04-20 14:14 youngturk 閱讀(245) 評論(0) 編輯 收藏 所屬分類: Oracle