代码如下 |
复制代码 |
create or replace procedure drop_all as cursor cur_obj is
select uo.OBJECT_NAME, uo.OBJECT_TYPE
from user_objects uo
where uo.OBJECT_NAME not in ('DROP_ALL')
and uo.OBJECT_TYPE not in ('LOB');
/* cursor cur_tablespace is
select ut.TABLESPACE_NAME
from user_tablespaces ut
where ut.TABLESPACE_NAME not in
('SYSTEM', 'SYSAUX', 'UNDOTBS1', 'TEMP', 'USERS');*/
v_obj_name user_objects.OBJECT_NAME%type;
v_obj_type user_objects.OBJECT_TYPE%type;
/* v_tablespaces_name user_tablespaces.TABLESPACE_NAME%type;*/
sql_str1 varchar2(2000);
/* sql_str2 varchar2(2000);*/
begin
open cur_obj;
loop
fetch cur_obj
into v_obj_name, v_obj_type;
exit when cur_obj%notfound;
sql_str1 := 'drop ' || v_obj_type || ' ' || v_obj_name;
execute immediate sql_str1;
end loop;
close cur_obj;
/* open cur_tablespace;
loop
fetch cur_tablespace
into v_tablespaces_name;
exit when cur_tablespace%notfound;
sql_str2 := 'drop tablespace ' || v_tablespaces_name ||
' including contents';
execute immediate sql_str2;
end loop;
close cur_tablespace;*/
end drop_all;
|
这个存储过程可以一把删掉用户下几乎所有的对象。注释里的东西释放出来就能删除表空间了。这个过程不能回滚,绝对不要在生产环境或者有用的环境上使用。我不对这个过程执行的结果负任何责任