Dynamically Clean up the target Oracle DB
- This job will call a main script. This script will first call a pre-defiend SQL file by replacing the proper DB USERNAME.
SPOOL /home/tmp/drop.sqlselect'drop table '||owner ||'.'||table_name||' cascade constraint;'as LBL_SCRIPT from all_tables where owner = upper('#_dbuser_#');select'drop sequence '||sequence_owner||'.'||sequence_name||';'as LBL_SCRIPT from all_sequences where sequence_owner = upper('#_dbuser_#');select'drop PROCEDURE '||object_name||';'as LBL_SCRIPT from ALL_OBJECTS where OWNER = upper('#_dbuser_#') and OBJECT_TYPE IN ('PROCEDURE');select'drop FUNCTION '||object_name||';'as LBL_SCRIPT from ALL_OBJECTS where OWNER = upper('#_dbuser_#') and OBJECT_TYPE IN ('FUNCTION');SPOOL OFFexit - The script will then try to select out the table,sequence,procedure and function from the target DB and paste it into a sql file by executing the SQL file in previous step.
########################################## generate the drop scriptforexisting db#########################################function generate_drop_script{echo"generate the drop script"sqlplus $dbuser/$dbpassword@ORCL@$gropFileecho"remove unwanted lines int the drop script"sed -i -e's/[0-9]*.*row.*//ig'$finalDropFilesed -i -e's/LBL_SCRIPT//g'$finalDropFileecho"append exit command to the drop script"echo"exit;">> $finalDropFile} - The script will remove those unwanted characters/words from the generated sql file in previous step.
- Execute the generated sql file to clean up the DB.
No comments:
Post a Comment