Shell script to DROP an Oracle Database

Many times when cloning a database we might need to drop the previous database and recreate it using the clone. For this, I am sharing a simple shell script to drop the database easily. You can change the code as per your requirement and customize it.

Note: Using the script is totally at your discretion, or you can use individual steps to drop the database manually. Do not use if you are not sure about Oracle database drop.


echo "Sourcing the environment"
. .bash_profile
echo "Check the Database Name $ORACLE_SID"
echo "ctrl + c to cancel this script"
sleep 30
sqlplus /nolog <<  EOF
connect / as sysdba
shutdown abort
startup mount exclusive
alter system enable restricted session;
rman target / <<EOF
drop database NOPROMPT;
lsnrctl stop $ORACLE_SID
lsnrctl start $ORACLE_SID

If you like please follow and comment