以前批量删除用户对象都用:drop user xxx cascade;不过有时如果条件不允许就得想些其他批量删除方法,看到网上一些朋友总结的,摘录如下:
1、-------->>
select 'Drop table '||table_name||';'
from all_tables
where owner='要删除的用户名(注意要大写)';
2、--------->>
删除所有表
以用户test为例
for example:
declare
cursor cur1 is select table_name from dba_tables where owner='TEST';
begin
for cur2 in cur1 loop
execute immediate 'drop table test.'||cur2.table_name;
end loop;
end;
3、这个删除当前用户的所有对象(表、视图、触发器、存储过程、函数)
没试过
DECLARE
TYPE name_list IS TABLE OF VARCHAR2(40);
TYPE type_list IS TABLE OF VARCHAR2(20);
Tab_name name_list:=name_list();
Tab_type type_list:=type_list();
sql_str VARCHAR2(500);
BEGIN
sql_str := 'select uo.object_name,uo.object_type from user_objects uo where uo.object_type not in(''INDEX'',''LOB'') order by uo.object_type desc';
EXECUTE IMMEDIATE sql_str BULK COLLECT INTO tab_name,tab_type;
FOR i IN Tab_name.FIRST.. Tab_name.LAST LOOP
sql_str := 'DROP ' || Tab_type(i) || ' ' || Tab_name(i);
EXECUTE IMMEDIATE sql_str;
END LOOP;
END;
1、-------->>
select 'Drop table '||table_name||';'
from all_tables
where owner='要删除的用户名(注意要大写)';
2、--------->>
删除所有表
以用户test为例
for example:
declare
cursor cur1 is select table_name from dba_tables where owner='TEST';
begin
for cur2 in cur1 loop
execute immediate 'drop table test.'||cur2.table_name;
end loop;
end;
3、这个删除当前用户的所有对象(表、视图、触发器、存储过程、函数)
没试过
DECLARE
TYPE name_list IS TABLE OF VARCHAR2(40);
TYPE type_list IS TABLE OF VARCHAR2(20);
Tab_name name_list:=name_list();
Tab_type type_list:=type_list();
sql_str VARCHAR2(500);
BEGIN
sql_str := 'select uo.object_name,uo.object_type from user_objects uo where uo.object_type not in(''INDEX'',''LOB'') order by uo.object_type desc';
EXECUTE IMMEDIATE sql_str BULK COLLECT INTO tab_name,tab_type;
FOR i IN Tab_name.FIRST.. Tab_name.LAST LOOP
sql_str := 'DROP ' || Tab_type(i) || ' ' || Tab_name(i);
EXECUTE IMMEDIATE sql_str;
END LOOP;
END;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29119536/viewspace-1097206/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29119536/viewspace-1097206/