Skip to content

Instantly share code, notes, and snippets.

@finsterthecat
Created January 25, 2011 23:01
Show Gist options
  • Select an option

  • Save finsterthecat/795886 to your computer and use it in GitHub Desktop.

Select an option

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.
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;
/
@finsterthecat
Copy link
Author

After dropping everything you may wish to import a dump file. Instructions are here:

http://www.orafaq.com/wiki/Import_Export_FAQ

@finsterthecat
Copy link
Author

You will want to purge the recyclebin since it will be full of everything you just dropped:

purge recyclebin;

@finsterthecat
Copy link
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);

@finsterthecat
Copy link
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