Created
January 25, 2011 23:01
-
-
Save finsterthecat/795886 to your computer and use it in GitHub Desktop.
Oracle script: Drop everything for your user. Handy when you can't just delete your user.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| declare | |
| stringa varchar2(100); | |
| cursor cur is | |
| select * | |
| from user_objects; | |
| begin | |
| for c in cur loop | |
| begin | |
| stringa := | |
| case c.object_type | |
| when 'VIEW' then 'drop view ' || c.object_name | |
| when 'TABLE' then 'drop table ' || c.object_name || ' cascade constraints' | |
| when 'SEQUENCE' then 'drop sequence ' || c.object_name | |
| when 'PACKAGE' then 'drop package ' || c.object_name | |
| when 'PROCEDURE' then 'drop procedure ' || c.object_name | |
| when 'FUNCTION' then 'drop function ' || c.object_name | |
| when 'INDEX' then 'drop index ' || c.object_name | |
| when 'PACKAGE BODY' then 'drop package body ' || c.object_name | |
| when 'DATABASE LINK' then 'drop database link ' || c.object_name | |
| else '' | |
| end; | |
| EXECUTE immediate stringa; | |
| exception | |
| when others then | |
| null; | |
| end; | |
| end loop; | |
| end; | |
| / |
Author
Author
You will want to purge the recyclebin since it will be full of everything you just dropped:
purge recyclebin;
Author
When exporting specify no statistics:
exp user/pass@db file=dbname.dmp statistics=none
Then after you've imported (after dropping everything):
imp user/pass@db file=dbname.dmp full=yes
You should regen the stats (in sqlplus):
SQL> EXEC dbms_stats.gather_schema_stats(’user', cascade=>TRUE);
Author
Finally got around to testing recent changes. This last one (ed80db) seems to work.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After dropping everything you may wish to import a dump file. Instructions are here:
http://www.orafaq.com/wiki/Import_Export_FAQ