#!/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
马克斯说的是正确的.尝试这个修改的脚本
原文链接:https://www.f2er.com/oracle/205440.html#!/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了解更多信息.