The shell script is used to export the DB2 database table to a file, and in another blog post, Java code calls the shell script and passes in the parameter implementation DB2 database table export to a file to invoke the script and pass in the parameters through Java code implementation.
#!/usr/bin/env shdbschema=$1dbuser=$2dbpassword=$3tablename=$4filepath=$5delimiter=$6exportlimit=$7sqlerr = "No error msg" ############################################################# : wlog string ########################################################### #wlog () { wlog_dt= ' date "+%y/%m/%d-%h:%m:%s" " echo " \n${wlog_dt} $1 "}####### ###################################################### : db2connect db2connstring############## ############################################# #connDB2 () {wlog "====================connect to $1======================= " wlog " Db2 connect to $1 user $2 "# #conn =db2 connect to $1 user $2 using $3 > / Dev/nullif ( db2 connect to $1 user $2 using $3 > /dev/ null ) thenwlog " succeed connect to $1 "elsewlog " failed connect to $1 "exit -1fi}############################################################# : db2connectrelease db2connstring########################################################### #releaseDB2 () {db2 connect reset > /dev/null}############################################################# : db2export########################################################### #exportDB2 () {conndb2 ${ Dbschema} ${dbuser} ${dbpassword}sql= " select * from ${tablename} ${ Exportlimit} "wlog " export to ${filepath} of del modified by codepage= 1208 coldel| ${sql}: "db2 " export to ${filepath} of del modified by nochardel codepage=1208 coldel| ${sql} "}######################################### #################### : main########################################################### #run () {#connDB2 ${dbnode} ${dbuser} ${dbpassword} ${dbname} #sql = " select inter_no,op_time from inter _log "#db2 -x ${sql}| while read inter_no op_time#do#echo " result:${ Inter_no}->${op_time} "#doneecho begin to export the data: " Exportdb2echo "Close the connection." releasedb2}echo "execute sql , .........." Run
The following export commands will strip the double quotes of the strings in the exported file:
DB2 "Export to ${filepath} of Del modified by Nochardel codepage=1208 coldel| ${sql} "
Coldel specifies that the delimiter is |
If you need to keep the string double quote command:
DB2 "Export to ${filepath} of Del modified by codepage=1208 coldel| ${sql} "
This article is from the "forever_love_ing" blog, make sure to keep this source http://dwf07223.blog.51cto.com/8712758/1553382
Shell script Implementation DB2 database table export to file