Clear Oracle Schema
/***********************************************************
WARNING!!!!!!
This script will delete all objects (Including tables
and data) for the currently logged in user. There is
no way to recover information deleted by this script.
Use this script with caution.
If you really do want to clear your schema, just paste
this script into your Oracle SQL window and click
the "Run Script" button.
***********************************************************/
BEGIN
FOR cur_rec IN (SELECT object_name, object_type
FROM user_objects
WHERE object_type IN
('TABLE',
'VIEW',
'PACKAGE',
'PROCEDURE',
'FUNCTION',
'SEQUENCE',
'TYPE',
'SYNONYM',
'MATERIALIZED VIEW'
))
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_syn IN (SELECT synonym_name
FROM all_synonyms
WHERE table_owner = (select user from dual))
LOOP
BEGIN
EXECUTE IMMEDIATE 'drop public synonym ' || cur_syn.synonym_name ;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.PUT_LINE ('Failed to drop the public synonym ' || cur_syn.synonym_name || '! ' || sqlerrm);
END;
END LOOP;
END;
/
purge recyclebin;
select * from cat;