Apagar esquemas rápido

O script de hoje ira te ajudar a apagar de forma rápida um esquema:

SET SERVEROUTPUT ON
DECLARE V_ESQUEMA VARCHAR2(30) := 'DBAPS';
BEGIN
  FOR APAGAR IN (  
                    SELECT 'DROP TABLE '||'"'||OWNER||'"'||'.'||'"'||OBJECT_NAME||'"'|| ' CASCADE CONSTRAINTS PURGE' DDL FROM DBA_OBJECTS WHERE OWNER = V_ESQUEMA AND OBJECT_TYPE='TABLE'
                    UNION ALL
                    SELECT 'DROP SEQUENCE '||'"'||OWNER||'"'||'.'||'"'||OBJECT_NAME||'"' DDL FROM DBA_OBJECTS WHERE OWNER = V_ESQUEMA AND OBJECT_TYPE='SEQUENCE'
                    UNION ALL
                    SELECT 'DROP VIEW '||'"'||OWNER||'"'||'.'||OBJECT_NAME DDL FROM DBA_OBJECTS WHERE OWNER = V_ESQUEMA AND OBJECT_TYPE='VIEW'
                    UNION ALL
                    SELECT 'DROP PROCEDURE '||'"'||OWNER||'"'||'.'||OBJECT_NAME DDL FROM DBA_OBJECTS WHERE OWNER = V_ESQUEMA AND OBJECT_TYPE='PROCEDURE'
                    UNION ALL
                    SELECT 'DROP FUNCTION '||'"'||OWNER||'"'||'.'||OBJECT_NAME DDL FROM DBA_OBJECTS WHERE OWNER = V_ESQUEMA AND OBJECT_TYPE='FUNCTION'
                    UNION ALL
                    SELECT 'DROP INDEX '||'"'||OWNER||'"'||'.'||'"'||INDEX_NAME||'"'|| ';' DDL FROM DBA_INDEXES WHERE OWNER = V_ESQUEMA
                    UNION ALL
                    SELECT 'DROP TYPE '||'"'||OWNER||'"'||'.'||'"'|| OBJECT_NAME||'"' || ' FORCE;' FROM DBA_OBJECTS WHERE OBJECT_TYPE ='TYPE' AND OWNER=V_ESQUEMA
                ) 
  LOOP
     DBMS_OUTPUT.PUT_LINE(APAGAR.DDL||' EXECUTADO.');
     EXECUTE IMMEDIATE APAGAR.DDL;
  END LOOP;
END;
/
SQL

Leave a Reply

Your email address will not be published. Required fields are marked *

search previous next tag category expand menu location phone mail time cart zoom edit close