bash - 当使用“WHENEVER SQLERROR EXIT 1”时,为什么 Sqlplus bash 脚本不返回 ORA-02291 完整性约束的错误?
问题描述
我编写了一个 bash 脚本来连接到 sqlplus 并执行特定文件夹中的所有 sql 脚本。下面是脚本的执行方法。
execute() {
if [ ! -d "$DIR_SqlFiles" ]
then
echo "No sql files were found. Cannot find path ${DIR_SqlFiles}"
return 1
fi
echo "`date` :Connecting To ${userName}/******@${serviceName}";
for file in `ls ${DIR_SqlFiles}/*` ; do
echo "`date` :Executing file $file..."
echo "`date` :SQL OUTPUT:";
sqlplus -s ${userName}/${password}@${host}:${port}/${serviceName} <<EOF
WHENEVER OSERROR EXIT 1 ROLLBACK;
WHENEVER SQLERROR EXIT 1 ROLLBACK
@${file};
commit;
quit;
EOF
sql_return_code=$?
if [ ${sql_return_code} != 0 ]
then
echo "`date` ${file} failed"
echo "Error code ${sql_return_code}"
return 1;
fi
done
echo "`date` :completed running all sql scripts in the ${DIR_SqlFiles} folder."
return 0;
}
问题是当 .sql 文件之一具有 ORA-02291:完整性约束时,此脚本不会失败。它返回 0,它只打印“0 行更新”而不打印实际错误。
在其他情况下,它工作正常。例如,如果表名错误(ORA-00942:表或视图不存在),脚本将失败并返回 1。
谁能指出我正确的方向。为什么对于第一种情况错误它没有失败?
解决方案
推荐阅读
- json - 如何从 POSTing text/turtle 返回到 Blazegraph?
- android - 无法在android中使用jobDispatcher创建作业
- r - 在 R 中按 3 列将数据框拆分为所有可能的数据框组合
- javascript - 让堆栈导航器始终呈现 initialRoute
- matlab - 从 94*263 特征向量中选择特征时,MATLAB 序列化时出错
- android - 如何在android中制作这样的径向浮动动作按钮?
- .net - IIS 7.5 .NET 共享 DLL 访问被拒绝错误
- spring-security - SAML 断言失败
- css - 浮动在标题中,导航列表和浏览器边缘之间没有间隙
- javascript - jQuery
- 事件没有触发