简体   繁体   English

通过Shell脚本执行合并时出错

[英]Error while executing Merge through shell script

I am trying to execute a script which calls Merge statement through sqlplus. 我正在尝试执行一个通过sqlplus调用Merge语句的脚本。

The merge statement is executing fine but when I am executing it through shell script, it's giving an error : merge语句执行得很好,但是当我通过shell脚本执行它时,出现了错误:

current_time=`date`
echo "FSG_PRCB_PRVD_FAC_SEQ table UPDATE STARTED at $current_time"
Result=`sqlplus -s $TgtUsrID/$TgtPswd@$TgtServer <<eof
whenever sqlerror exit sql.sqlcode; 
merge into FSG_WRK.FSG_PRCB_FAC_REF_DATA T1
   using
    (select NUM_ID, ALPHA_NUM_ID from FSG.FSG_PRCB_ADDRESS_CROSSWLK) T2
  ON (T1.ADDR_TYPE=T2.ALPHA_NUM_ID)
when matched then
     update set T1.ADDR_TYPE_N = T2.NUM_ID ;
eof
`

ERRORCODE=$?

#Check the return code from SQL Plus
if [ $ERRORCODE != 0 ]
then
  echo "********************"
  echo "ERROR: Updating Status Failed. ErrorCode: $ERRORCODE"
  exit -1
else
  echo "********************"
  echo "UUpdating Status  returns $Result"
       current_time=`date`
       echo "Updating Status Query finished at $current_time"
fi

Output : 输出:

updating status failed.Errorcode:174 更新状态失败。错误代码:174

I am not sure what went wrong. 我不确定出了什么问题。

Using exit sql.sqlcode can be misleading, or even dangerous. 使用exit sql.sqlcode可能会引起误解,甚至是危险的。

From The Linux Documentation Project : 来自Linux文档项目

Out of range exit values can result in unexpected exit codes. 超出范围的退出值可能会导致意外的退出代码。 An exit value greater than 255 returns an exit code modulo 256. For example, exit 3809 gives an exit code of 225 (3809 % 256 = 225). 大于255的退出值将返回以256为模的退出代码。例如,出口3809给出的退出代码为225(3809%256 = 225)。

You're seeing the exit code reported as 174, but the original error code could have been anything where mod(<actual code>, 256) evaluates to 174. You'll be able to see the actual error code and message in your $Result variable. 您看到的退出代码报告为174,但是原始错误代码可能是mod(<actual code>, 256)计算为174的任何内容。您将能够在$Result看到实际的错误代码和消息。 $Result变量。

A likely candidate is an ORA-00942 error (as mod(942, 256) is 174) - and as you've said the merge works standalone, you'll probably find that the user you're connecting to and running the merge as, represented by $TgtUsrID , does not have the necessary privileges on the tables owned by FSG and/or FSG_WRK . 可能的候选者是ORA-00942错误(因为mod(942, 256)为174)-正如您所说的合并是独立运行的,您可能会发现您正在连接并以以下身份运行该用户由$TgtUsrID表示的对FSG和/或FSG_WRK拥有的表没有必需的特权。

This shows that the reported exit code can be confusing or misleading. 这表明报告的退出代码可能会造成混淆或误导。 The potentially dangerous part if if you get a real error code which is an exact multiple of 256, such as the plausible ORA-01536 "space quota exceeded for tablespace %s'. As mod(1536, 256) is zero, $ERRORCODE will be zero too, so your check: 如果您得到的实际错误代码是256的整数倍,则可能是危险的部分,例如,合理的ORA-01536“表空间%s的空间配额超出了。由于mod(1536, 256)为零, $ERRORCODE将也为零,所以您的检查:

if [ $ERRORCODE != 0 ]

will be false even though an error did occur. 即使确实发生错误,也会为假。

It will probably be simpler to change your SQL to have whenever sqlerror exit failure (maybe with the addition of rollback ?), and then your check for non-zero will work; whenever sqlerror exit failure更改您的SQL可能会更简单(也许添加了rollback吗?),然后您可以检查非零值。 and you can use $Result to see/report what was actually wrong. 您可以使用$Result查看/报告实际出了什么问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过phpMyAdmin执行MySql#1243错误 - MySql #1243 error while executing it through phpMyAdmin 通过phpMyAdmin执行MySql#1054错误 - MySql #1054 error while executing it through phpMyAdmin 通过 shell 脚本执行 BTEQ 文件(BTEQ:找不到命令错误) - Executing BTEQ file via shell script (BTEQ: Command not found error) 通过shell脚本调用sql过程,如果发生错误则通过电子邮件发送 - Call sql procedure through a shell script and email if error SQL 文件通过 shell 脚本执行没有错误但也没有结果 - SQL file executes with no error but also no results through shell script 如何在 shell 脚本中执行 sql 文件时也在日志文件中显示 sql 语句 - how to display sql statements also in log file while executing the .sql file in shell script 执行 perl 脚本时出错,无法设置环境变量 - Error while executing the perl script and not able to set the Environment Variables 执行SQL脚本时出错,但单独运行时则不出错 - Error while executing SQL script but not when running individually 执行BCP脚本时出错-必须声明标量变量@v - Error while executing BCP Script - Must declare the scalar variable @v 使用Shell脚本创建报告时出现格式错误 - Formatting error while creating report using Shell Script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM