【问题标题】:sqlplus within a loop - unix循环中的 sqlplus - unix
【发布时间】:2018-06-02 17:12:24
【问题描述】:

有没有办法在一个循环中发送多个 sqlplus 命令但等待一个成功运行以便下一个启动? 这是我的代码示例。我试图添加 sleep 15 因为我要执行的功能需要 10-20 秒才能运行。我想摆脱那个 15s 常数,让它们一个接一个地运行。

if [ "$#" -eq 1 ]; then
   checkUser "$1"
   while read line; do
     sqlplus $user/$pass@$server $line
     sleep 15
   done < "$wrapperList"
fi

【问题讨论】:

  • 哦,我还以为是要并行发送sqlplus命令呢。它只是将在 sqlplus 命令中使用的 .sql 文件的列表。没试过,这是我的第一个假设。我会尝试,我会回来回答。谢谢

标签: oracle shell unix plsql sqlplus


【解决方案1】:

while 循环中的指令按顺序执行。相当于这样做,使用; 链接指令:

sqlplus $user/$pass@$server $line1 
sqlplus $user/$pass@$server $line2

所以你在这里不需要sleep 15,因为sqlplus 命令不会被并行调用。您已经这样做的方式是一个接一个地调用它们。

注意:如果第一行没有正确返回,最好停止运行,使用&amp;&amp; 表示:仅当先前的返回码为0 时才运行

sqlplus $user/$pass@$server $line1 &&\ 
sqlplus $user/$pass@$server $line2

在while循环中有这个:

   checkUser "$1"
   while read line; do
     sqlplus $user/$pass@$server $line
     RET_CODE=$? # check return code, and break if not ok.
     if [ ${RET_CODE} != 0 ]; then
       echo "aborted." ; break
     fi
   done < "$wrapperList"

另一方面,当你想并行运行时,语法是不同的,比如这里:Unix shell script run SQL scripts in parallel

【讨论】:

    猜你喜欢
    • 2021-05-23
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    • 2016-05-21
    • 1970-01-01
    • 2011-06-06
    • 1970-01-01
    • 2011-06-07
    相关资源
    最近更新 更多