Shell指令碼實現DB2資料庫表匯出到檔案

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   java   ar   檔案   

  該Shell指令碼用於實現將DB2資料庫表匯出到檔案,將在另一篇博文《Java代碼調用Shell指令碼並傳入參數實現DB2資料庫表匯出到檔案》中通過Java代碼實現調用該指令碼並傳入參數。

 1 #!/usr/bin/env sh 2   3 DBSCHEMA=$1 4 DBUSER=$2 5 DBPASSWORD=$3 6 TABLENAME=$4 7 FILEPATH=$5 8 DELIMITER=$6 9 EXPORTLIMIT=$710  11 SQLERR="NO ERROR MSG"12  13 ############################################################14 # : wlog String  15 ############################################################16 wlog () {17    wlog_dt=`date "+%Y/%m/%d-%H:%M:%S" `18    echo "\n${wlog_dt} $1"19 }20  21 ############################################################22 # : db2connect db2connstring23 ############################################################24 connDB2() {25     wlog "====================connect to $1=======================" 26      wlog "db2 connect to $1 user $2 "27 ##  conn=db2 connect to $1 user $2 using $3 > /dev/null28     if( db2 connect to $1 user $2 using $3 > /dev/null )29     then30         wlog "Succeed connect to $1 "31     else32         wlog "Failed connect to $1 "33         exit -134     fi35 }36  37 ############################################################38 # : db2connectRelease db2connstring39 ############################################################40 releaseDB2() {41     db2 connect reset  > /dev/null42 }43  44 ############################################################45 # : db2export46 ############################################################47 exportDB2() {48     connDB2 ${DBSCHEMA} ${DBUSER} ${DBPASSWORD}49     sql=" select * from ${TABLENAME} ${EXPORTLIMIT}"50     wlog "export to ${FILEPATH} of del modified by codepage=1208 COLDEL| ${sql}: "51     db2 "export to ${FILEPATH} of del modified by nochardel codepage=1208 COLDEL| ${sql}"52 }53  54 ############################################################55 # : main56 ############################################################57 run() {58 #   connDB2 ${DBNODE} ${DBUSER} ${DBPASSWORD} ${DBNAME}59 #   sql=" select inter_no,op_time from inter_log "60      61 #   db2 -x ${sql}| while read inter_no op_time62 #   do63 #       echo "Result:${inter_no}->${op_time}"64 #   done65  66     echo "Begin to export the data: "67     exportDB268  69     echo "Close the connection."70     releaseDB271 }72  73 echo "execute sql ................."74 run

 

其中以下匯出命令將會去除匯出檔案中字串的雙引號:

1 db2 "export to ${FILEPATH} of del modified by nochardel codepage=1208 COLDEL| ${sql}"

 

COLDEL指定了分隔字元為|

 

如果需要保留字元串雙引號命令:

1 db2 "export to ${FILEPATH} of del modified by codepage=1208 COLDEL| ${sql}"

 

Shell指令碼實現DB2資料庫表匯出到檔案

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.