【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
开发一个PL/SQL块,删除某个用户的所有表 就遍历 user_tables表,查询这个用户的所有表,组成SQL语句(drop语句),执行 Drop就可以了。
declare cursor cur is select table_name from user_tables; cursor cur2 is select constraint_name,table_name from user_constraints where constraint_type='R'; tname varchar(30); cname varchar(30); vsql varchar(100); begin open cur2; loop fetch cur2 into cname,tname; exit when cur2%notfound; vsql:='alter table '||tname||' drop constraint '||cname; dbms_output.put_line(vsql); EXECUTE IMMEDIATE vsql; end loop; close cur2; open cur; loop fetch cur into tname; exit when cur%notfound; vsql:='drop table '||tname; dbms_output.put_line(vsql); --执行上面的vsql,将这个vsql语句让Oracle数据来执行 EXECUTE IMMEDIATE vsql; end loop; close cur; end;
select constraint_name,table_name from user_constraints where constraint_type='R';
实现删除里面的所有 view,triiger,procedure
create or replace procedure p1 as cursor cur is select table_name from user_tables; cursor cur2 is select constraint_name,table_name from user_constraints where constraint_type='R'; tname varchar(30); cname varchar(30); vsql varchar(100); begin open cur2; loop fetch cur2 into cname,tname; exit when cur2%notfound; vsql:='alter table '||tname||' drop constraint '||cname; dbms_output.put_line(vsql); EXECUTE IMMEDIATE vsql; end loop; close cur2; open cur; loop fetch cur into tname; exit when cur%notfound; vsql:='drop table '||tname; dbms_output.put_line(vsql); --执行上面的vsql,将这个vsql语句让Oracle数据来执行 EXECUTE IMMEDIATE vsql; end loop; close cur; end;
exec p1;
来源:oschina
链接:https://my.oschina.net/u/2510566/blog/661507