Oracle script

A coworker gave me this script and it rules:


set pause off
set echo off
set scan on
set verify off
set pagesize 0
set feedback off
set recsep off
set termout off
spool drop_&1._objects.sql
select 'spool drop_&1._objects.log'
from dual
/
select 'drop ' || object_type || ' ' || owner || '.' || object_name
|| decode(object_type,
'CLUSTER', ' including tables cascade constraints;',
'TABLE', ' cascade constraints;',
';')
from dba_objects
where owner = upper('&1')
and object_type in ('CLUSTER', 'TABLE', 'VIEW', 'SEQUENCE', 'SYNONYM',
'FUNCTION',
'PROCEDURE', 'PACKAGE')
/
select 'spool off'
from dual
/
spool off
set feedback on
set pagesize 24
set termout on
prompt Run @drop_&1._objects to drop &1's objects ...

Run that in sqlplus and it will output another script that will drop all your sequences and tables in a DB,. Very handy for development. Don’t forget to have a dump of data incase you need to get back to where you were :)

About Nathan Powell

I am a middle aged technologist freak-ball.
This entry was posted in computers. Bookmark the permalink.

Comments are closed.