您好,欢迎访问一九零五行业门户网

sql存储过程删除用户下所有对象语句

一个开发中可能会碰到的sql语句,我们利用sql存储过程删除用户下所有对象,有需要的同学可以参考一下哦,很简单的。
 代码如下 复制代码
create or replace procedure drop_all as  cursor cur_obj is
    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;
这个存储过程可以一把删掉用户下几乎所有的对象。注释里的东西释放出来就能删除表空间了。这个过程不能回滚,绝对不要在生产环境或者有用的环境上使用。我不对这个过程执行的结果负任何责任
其它类似信息

推荐信息