Return value from sql script to shell script

前端 未结 2 1113
小蘑菇
小蘑菇 2020-12-06 07:16

I have shell script that calls the following sql script:

     INSERT INTO SEMANTIC.COUNT_STATISTICS (...);
     UPDATE SEMANTIC.COUNT_STATISTICS 
     SET PR         


        
2条回答
  •  醉话见心
    2020-12-06 07:50

    What I actually did is I separated those 2 queires and called them separatelly in my shell script:

    sqlplus -S user/pass << EOF
    whenever sqlerror exit 1;
    set echo on
    @/opt/D2RQ/model_count.sql '$MODEL'  <--model_count.sql still has those INSERT & UPDATE statements
    exit;
    EOF
    
    model_count=`sqlplus -S user/pass << EOF
    SELECT PRNCT_CHANGE
     FROM COUNT_STATISTICS
    WHERE model = '$MODEL'
    AND NEW_DATE = (
                    select max(NEW_DATE)
                    from COUNT_STATISTICS
                    where MODEL = '$MODEL'
                   );
    exit;
    EOF`
    
    
    if [ $model_count >= 0 ]; then
        echo "$model_count"
    else
             echo "'$MODEL' is negative " | mail -s "scripts issues" -c angelina1984@aol.com
    fi
    

提交回复
热议问题