Oracle中删除用户下所有对象
sql语句:
DECLARE
TYPE name_list IS TABLE OF VARCHAR2(100);
TYPE type_list IS TABLE OF VARCHAR2(100);
--表对象
Tab_name name_list := name_list();
Tab_type type_list := type_list();
sql_str VARCHAR2(1000);
BEGIN
sql_str := 'SELECT UO.OBJECT_NAME,UO.OBJECT_TYPE FROM USER_OBJECTS UO WHERE UO.OBJECT_TYPE NOT IN (''INDEX'',''LOB'') AND SUBSTR(UO.OBJECT_NAME,4) <> ''BIN$'' ORDER BY UO.OBJECT_NAME ASC';
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)||'" CASCADE CONSTRAINTS';
dbms_output.put_line(sql_str);
EXECUTE IMMEDIATE sql_str;
END LOOP;
dbms_output.put_line('已成功删除对象');
END;
/