Shell script Implementation DB2 database table export to file

Source: Internet
Author: User


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&nbsp, .........." 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.