開發一個PL/SQL塊,刪除某個用戶的全部表 就遍歷 user_tables表,查詢這個用戶的全部表,組成SQL語句(drop語句),執行 Drop就能夠了。sql
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;oop
select constraint_name,table_name from user_constraints where constraint_type='R';fetch
實現刪除裏面的全部 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;it
exec p1;table