Answers for "how to drop all the tables in oracle"

SQL
2

delete all table oracle

BEGIN
   FOR cur_rec IN (SELECT object_name, object_type
                   FROM user_objects
                   WHERE object_type IN
                             ('TABLE',
                              'VIEW',
                              'MATERIALIZED VIEW',
                              'PACKAGE',
                              'PROCEDURE',
                              'FUNCTION',
                              'SEQUENCE',
                              'SYNONYM',
                              'PACKAGE BODY'
                             ))
   LOOP
      BEGIN
         IF cur_rec.object_type = 'TABLE'
         THEN
            EXECUTE IMMEDIATE 'DROP '
                              || cur_rec.object_type
                              || ' "'
                              || cur_rec.object_name
                              || '" CASCADE CONSTRAINTS';
         ELSE
            EXECUTE IMMEDIATE 'DROP '
                              || cur_rec.object_type
                              || ' "'
                              || cur_rec.object_name
                              || '"';
         END IF;
      EXCEPTION
         WHEN OTHERS
         THEN
            DBMS_OUTPUT.put_line ('FAILED: DROP '
                                  || cur_rec.object_type
                                  || ' "'
                                  || cur_rec.object_name
                                  || '"'
                                 );
      END;
   END LOOP;
   FOR cur_rec IN (SELECT * 
                   FROM all_synonyms 
                   WHERE table_owner IN (SELECT USER FROM dual))
   LOOP
      BEGIN
         EXECUTE IMMEDIATE 'DROP PUBLIC SYNONYM ' || cur_rec.synonym_name;
      END;
   END LOOP;
END;
/
Posted by: Guest on August-10-2021
3

oracle drop all schema tables

BEGIN
    FOR cur_rec IN (SELECT OBJECT_NAME, OBJECT_TYPE
                    FROM ALL_OBJECTS		-- Choose types
                    WHERE OBJECT_TYPE IN ('TABLE', 'VIEW', 'PACKAGE',
                                          'PROCEDURE', 'FUNCTION', 'SEQUENCE'))
                          AND OWNER = 'owner_name'
        LOOP
            BEGIN
                IF cur_rec.OBJECT_TYPE = 'TABLE'
                THEN
                    EXECUTE IMMEDIATE 'DROP ' || cur_rec.OBJECT_TYPE || ' "'
                        || cur_rec.OBJECT_NAME || '" CASCADE CONSTRAINTS';
                ELSE
                    EXECUTE IMMEDIATE 'DROP ' || cur_rec.OBJECT_TYPE || ' "'
                        || cur_rec.OBJECT_NAME || '"';
                END IF;
            EXCEPTION
                WHEN OTHERS
                    THEN
                        DBMS_OUTPUT.PUT_LINE('FAILED: DROP '
                            || cur_rec.OBJECT_TYPE || ' "'
                            || cur_rec.OBJECT_NAME || '"');
            END;
        END LOOP;
END;
Posted by: Guest on July-10-2021

Code answers related to "how to drop all the tables in oracle"

Code answers related to "SQL"

Browse Popular Code Answers by Language