oracle – 从shell脚本运行sqlplus时管理错误处理

前端之家收集整理的这篇文章主要介绍了oracle – 从shell脚本运行sqlplus时管理错误处理前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/bin/sh

echo "Please enter evaluate database username"
read eval_user
echo "Please enter evaluate database password"
read eval_pass
echo "Please enter the database name"
read db_name

LOGFILE=shell_log.txt

$ORACLE_HOME/bin/sqlplus -s /nolog <<-EOF>> ${LOGFILE}
connect $eval_user/$eval_pass@$db_name
WHENEVER OSERROR EXIT 9;
WHENEVER sqlERROR EXIT sql.sqlCODE;
DBMS_OUTPUT.put_line('Connected to db');
EOF

if [ $? != 0 ]
then 
echo "The upgrade script Failed. Please refer to the log results.txt for more information"
echo "Error code $?"
exit 0;
fi

我正在输入尝试强制此脚本失败的垃圾值.但是,令人烦恼的是,它不间断地提到任何错误代码.这里还需要做些什么?

马克斯说的是正确的.尝试这个修改的脚本
#!/bin/sh

echo "Please enter evaluate database username"
read eval_user
echo "Please enter evaluate database password"
read eval_pass
echo "Please enter the database name"
read db_name

LOGFILE=shell_log.txt

sqlplus -s /nolog <<-EOF>> ${LOGFILE}
WHENEVER OSERROR EXIT 9;
WHENEVER sqlERROR EXIT sql.sqlCODE;
connect $eval_user/$eval_pass@$db_name
DBMS_OUTPUT.put_line('Connected to db');
EOF

sql_return_code=$?

if [ $sql_return_code != 0 ]
then
echo "The upgrade script Failed. Please refer to the log results.txt for more information"
echo "Error code $sql_return_code"
exit 0;
fi

请注意使用sql_return_code来捕获sqlPLUS返回码.

DBMS_OUTPUT语句应该失败,并出现错误 – “SP2-0734:unknown命令开始…”.您可以在日志文件中找到错误消息.

可以使用错误记录工具捕获sqlPLUS 11g中的sp2错误.请查看http://tkyte.blogspot.co.uk/2010/04/new-thing-about-sqlplus.html了解更多信息.

原文链接:https://www.f2er.com/oracle/205440.html

猜你在找的Oracle相关文章