Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Oracle DB: Delete all user objects (Tables, Views, Procedures, Functions, Sequences, Types, Packages)
BEGIN
FOR record IN (SELECT object_name, object_type
FROM user_objects
WHERE object_type IN
('TABLE',
'VIEW',
'PROCEDURE',
'FUNCTION',
'SEQUENCE',
'TYPE',
'PACKAGE'
))
LOOP
BEGIN
IF record.object_type = 'TABLE'
THEN
EXECUTE IMMEDIATE 'DROP '
|| record.object_type
|| ' "'
|| record.object_name
|| '" CASCADE CONSTRAINTS';
ELSE
EXECUTE IMMEDIATE 'DROP '
|| record.object_type
|| ' "'
|| record.object_name
|| '"';
END IF;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ( 'FAILED: DROP '
|| record.object_type
|| ' "'
|| record.object_name
|| '"'
);
END;
END LOOP;
END;
/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.