This is an example of using scripts to update databases. the running environment is bashshell, the first parameter of shell is go, and the second parameter is a list of SQL files. the first parameter actually does not have any meaning, but it is best to still exist. It aims to run the script if someone who does not know the shell execution effect needs, when the go parameter is not added
This is an example of using scripts to update databases. the running environment is bash shell, the first parameter of shell is go, and the second parameter is a list of SQL files. the first parameter actually does not have any meaning, but it is best to still exist. It aims to run the script if someone who does not know the shell execution effect needs, when the go parameter is not added
This is an example of using scripts to update databases. The runtime environment is bash shell, the first parameter of shell is go, and the second parameter is a list of SQL files.
The first parameter actually does not have any meaning, but it is best to still exist. It aims to run the script if someone who does not know the shell execution effect needs, it is not executed when no go parameter is added. this ensures database security. the second parameter is a file list in the following format:
The exported file contains some SQL statements for insertion, update, and deletion.
The specific shell is as follows:
#! /Bin/sh # The following is an environment where TS_SYSTEM_DATE = 'date' + % m % d % H % M % s' TS _ ZHIXING_DATE = 'date' + % Y % m % d ''ora _ USR =$ {userid}/$ {password }@$ {instance}
TS_LOG_PATH =$ {LOG_DIR}/setupif test-d $ {TS_LOG_PATH} thenTS_RCODE = 0 elsemkdir-m 777 $ {TS_LOG_PATH} else =$ {DBBACKUP_DIR}/$ {region} _ test -d $ {TS_DBBACKUP_PATH} thenTS_RCODE = 0 elsemkdir-m 777-p $ {TS_DBBACKUP_PATH} fi
TS_LOGFILE =$ {TS_LOG_PATH}/SQL _EXEC _ $ {TS_SYSTEM_DATE}. logTS_QIAN = "QIAN" TS_HOU = "HOU" # SQL Execution handler =./SQLJIKKOU _ $ {TS_SYSTEM_DATE}. dat
TS_RCODE = 0
# The following three functions are extracted from the public functions. It is used multiple times, so it is proposed from the main shell function. # Check whether table_exist_check () {# The following statement returns the number of tables. It is usually 0, or 1, and the table existence is 1, no table is 0 TMPSTR = 'echo $ (sqlplus-s $ {ora_userid}/$ {ora_password }@$ {instance} <SQL _endselect count (tablename) from tab where tablename = upper ('$ 1'); exitsql_end) 'table _ NUM = 'echo $ {TMPSTR} | awk' {print $3 }''
If [["$ {TABLE_NUM}" = "0"]; then # echo "the number of tables $ {1} is 0 'date'" | tee-a $ {TS_LOGFILE} TS_RCODE = 1rm-r $ {TS_INPUT_FILE} exit $ {TS_RCODE} the TABLE processed by elseecho "" echo "++, $1 "return 0fi}
# Obtain the data before and after the table update, and then diff to check whether the expected results are achieved. table_QIAN_HOU (){
Sqlplus-s $ {ora_userid}/$ {ora_password }@$ {instance} <EOFEOF? >/Dev/nullset colsep ','; set echo off; set [...]
Original article address: update the shell script of the oracle database. Thank you for sharing it.