Shell script Implementation DB2 database table export to file

Source: Internet
Author: User
Tags db2 db2 connect db2 connect to

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.

1#!/usr/bin/Env SH2  3dbschema=$14dbuser=$25dbpassword=$36tablename=$47filepath=$58delimiter=$69exportlimit=$7Ten   OneSqlerr="NO ERROR MSG" A   - ############################################################ - #: Wlog String the ############################################################ - Wlog () { -Wlog_dt= 'Date "+%y/%m/%d-%h:%m:%s" ` -    Echo "\n${wlog_dt} $" + } -   + ############################################################ A #: DB2Connect db2connstring at ############################################################ - connDB2 () { -Wlog"====================connect to $1======================="  -Wlog"DB2 Connect to user $" -# # CONN=DB2 Connect to $1User $2Using $3>/dev/NULL -     if(DB2 Connect to $1User $2Using $3>/dev/NULL ) in      Then -Wlog"succeed Connect to $" to     Else +Wlog"Failed Connect to $" -Exit-1 the     fi * } $  Panax Notoginseng ############################################################ - #: Db2connectrelease db2connstring the ############################################################ + releaseDB2 () { ADB2 Connect reset >/dev/NULL the } +   - ############################################################ $ #: Db2export $ ############################################################ - exportDB2 () { - connDB2 ${dbschema} ${dbuser} ${dbpassword} theSql="select * from ${tablename} ${exportlimit}" -Wlog"Export to ${filepath} of Del modified by codepage=1208 coldel| ${sql}:"WuyiDb2"Export to ${filepath} of Del modified by Nochardel codepage=1208 coldel| ${sql}" the } -   Wu ############################################################ - #: Main About ############################################################ $ run () { - # connDB2 ${dbnode} ${dbuser} ${dbpassword} ${dbname} -# sql="Select Inter_no,op_time from Inter_log" -       A# db2-x ${sql}| whileRead Inter_no op_time +# Do the#Echo "Result:${inter_no}->${op_time}" -# Done $   the     Echo "Begin to export the data:" the exportDB2 the   the     Echo "Close the connection." - releaseDB2 in } the   the Echo "Execute SQL ... ..... ....." AboutRun

The following export commands will strip the double quotes of the strings in the exported file:

1 " 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:

1 " Export to ${filepath} of Del modified by codepage=1208 coldel| ${sql} "

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.