我是shell腳本的新手。 我正在寫一個DBA自動化的代碼,其中我有master.sql文件有n個sqls的聲明。這些sqls被放置在特定文件夾內。 我有一個腳本,調用此master.sql和一次間接執行的sql語句,並在一次 wwhat我想在如何在任何sql失敗時停止unix shell腳本中的sqlplus命令
sqlplus的命令是節省內部master.sql聲明的所有SQL的輸出的日誌文件保存是否它必須停止執行時,第一個sql失敗,並返回錯誤與特定的SQL失敗或要求回滾,並要求你想繼續或不? 每次嘗試使用sqlplus,sqlerror,$?毫無效果
sqlplus ${USER}/${PASS}@$SID @master.sql > /home/deploy/vidya/properties/result/result.log
現在我所試圖做的是....我希望在任何的sql從起點失敗,提示有錯誤的命令行上停止sql語句的執行和指定SQL失敗
master.sql
SET ECHO ON
@/home/deploy/vidya/properties/001_dba_demo.sql
@/home/deploy/vidya/properties/003_dba_demo1.sql
@/home/deploy/vidya/properties/002_dba_demo2.sql
@/home/deploy/vidya/properties/004_dba_demo2.sql
EXIT
這是調用master.sql其正常工作
我.SH腳本#!/bin/bash
echo "Enter schema Name you want to connect: "
read USER
echo "Enter password: "
read -s PASS
#echo "Enter Oracle SID for the environment you want to connect with : "
#read SID
echo "Enter Environment for the environment you want to connect with : "
read ENV
echo "Enter Oracle SID for the environment you want to connect with : "
read SID
export ORACLE_SID=${SID}
if [ $ENV == UAT ]
then
echo "Connected withh UAT ORACLE HOME:"
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/db_1
elif [ $ENV == PROD ]
then
echo "Connected with PROD ORACLE HOME:"
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/db_1
else
echo "Wrong Environment Entered :"
fi
export PATH=$ORACLE_HOME/bin:$PATH
echo "want to execute sql? y/n"
read yn
sqlplus ${USER}/${PASS}@$SID @master.sql > /home/deploy/vidya/properties/result/result.log
**
誰能幫**
[WHENEVER SQLERROR(HTTPS:/ /docs.oracle.com/cd/B19306_01/server.102/b14357/ch12052.htm)? – 7171u