如何在shell脚本中捕获SQLPlus退出代码?
发布时间:2020-12-15 18:24:55 所属栏目:安全 来源:网络整理
导读:我有一个Korn Shell(ksh)脚本,它登录到SQL * Plus并执行脚本.在shell脚本中,我想捕获已执行的SQL语句的状态代码.目前SQL存在错误,我无法通过检查$?来捕获它. 我如何从sql语句中捕获成功或错误代码并将其传递给shell脚本. 片段的ksh脚本: sqlplus $JDBC_FBU
我有一个Korn
Shell(ksh)脚本,它登录到SQL * Plus并执行脚本.在shell脚本中,我想捕获已执行的SQL语句的状态代码.目前SQL存在错误,我无法通过检查$?来捕获它.
我如何从sql语句中捕获成功或错误代码并将其传递给shell脚本. 片段的ksh脚本: sqlplus $JDBC_FBUID_U/$JDBC_FBPWD_U@$JDBC_FBDB @${FBC_HOME}/FBCS003.sql ${outputfile} if [ $? != 0 ] then msg_txt="The execution of Sql script /tmp/FBCS003.sql failed. Please investigate." echo ${msg_txt} echo ${msg_txt} | mailx -r ${fromemail} -s "FBCB003: The execution of Sql script /tmp/FBCS003.sql failed." ${toemail} epage -n ${pagerdef} ${pagernum} "FBCB003: ${msg_txt}" exit 1 fi SQL脚本FBCS003.sql -- Set SQLPlus variables. SET NEWPAGE 0 SET WRAP OFF SET LINESIZE 9999 SET ECHO OFF SET FEEDBACK OFF SET VERIFY OFF SET HEADING OFF SET PAGESIZE 0 SET COLSEP | SET TRIMSPOOL ON SET TIMING ON -- Open output file -- The file path and name are passed from the calling script FBCS003. spool &1 -- Main Select Statement select ct.fiscal_yr_no,ct.acct_per_no,ct.bus_unit_id,ct.btch_file_seq_no,ct.comm_tran_srce_cd,ct.rec_no,ct.rev_gl_acct_no,ct.gl_prod_cd,ct.prod_desc,ct.paid_ir_no,ct.srce_ir_no,ct.ir_no_house_acct_rsn_txt,ct.vndr_acct_ty_id,ct.clnt_na,ct.issr_na,ct.trd_da,ct.setl_da,ct.ord_ty_cd,ct.actv_ty_cd,ct.prin_amt,ct.grs_comm_amt,ct.net_comm_amt,ct.vndr_prod_ty_cd,ct.vndr_stmt_id from fin.comm_tran ct where ct.bus_unit_id = 'EJL' and ct.vndr_acct_ty_id in ('22222111','222222222') -- Execute sql statement. / -- Close output file spool off -- Exit SQL exit /
你尝试过使用过吗?
whenever sqlerror exit sql.sqlcode 在你的SQL脚本中? (另见this link) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |