home *** CD-ROM | disk | FTP | other *** search
- #! /bin/sh
-
- #
- # Drop all user objects from an Oracle database
- #
-
- usage() {
- echo "Usage: dropora [-n] <username/password>[@server]"
- echo ""
- echo "Note: This uses \$ORACLE_HOME/bin/sqlplus, so make sure that"
- echo " ORACLE_HOME is set. On an installation without SQL*Net,"
- echo " leave off the '@server' part, and make sure that"
- echo " ORACLE_SID is set to the system identifier."
-
- exit 1
- }
-
- if [ $# -lt 1 -o $# -gt 2 ]; then
- usage
- fi
-
- drop=1
- if [ $# = 2 ]; then
- if [ "$1" = "-n" ]; then
- drop=0
- shift
- else
- usage
- fi
- fi
-
- connect=$1
- tmp=/tmp/ora.$$
- shift
-
- $ORACLE_HOME/bin/sqlplus -s $connect <<EOF >$tmp
- set heading off
- set linesize 255
- select object_type, object_name from user_objects;
- EOF
-
- if [ "$drop" = "1" ]; then
-
- (
-
- grep '^TABLE' $tmp | awk '{print "DROP TABLE "$2";"}'
- grep -v '^TABLE' $tmp | awk '{if (NF == 2) print "DROP "$1" "$2";"}'
-
- ) | $ORACLE_HOME/bin/sqlplus -s $connect >/dev/null 2>&1
-
- else
-
- grep '^TABLE' $tmp | awk '{print "DROP TABLE "$2";"}'
- grep -v '^TABLE' $tmp | awk '{if (NF == 2) print "DROP "$1" "$2";"}'
-
- fi
-
- rm -f $tmp
- exit 0
-