Error out shell script if PL/SQL program fails











up vote
1
down vote

favorite












In the shell script, I am calling a PL/SQL stored procedure.



sqlplus -s <<EOF
$v_fcp_login
set head off feed off serverout on size 1000000
exec XXIRIS_TEST_K.XXIRIS_TEST('$v_1',$v_2,$v_3,'$v_4',$v_5);
exit
EOF


But when there is an error in the PL/SQL block, I need to error out shell script, which is running as a host concurrent program in Oracle, but it is not doing so.










share|improve this question
























  • if that block is normal shell code, then you need to use eval or run the script in a different manner — exec will substitute that shell with the call, so exit can never be reached. And to only exit on error, assuming plsql has sane exit codes, use || exit at the end of the call. It will still probably be moot, since it will only exit the current shell and you seem to want one more.
    – lynxlynxlynx
    Sep 30 '13 at 20:27










  • Just an FYI, when dealing with usernames/passwords with sqlplus you should be using Oracle Wallets: docs.oracle.com/cd/E25054_01/network.1111/e16543/…
    – slm
    Oct 1 '13 at 0:02















up vote
1
down vote

favorite












In the shell script, I am calling a PL/SQL stored procedure.



sqlplus -s <<EOF
$v_fcp_login
set head off feed off serverout on size 1000000
exec XXIRIS_TEST_K.XXIRIS_TEST('$v_1',$v_2,$v_3,'$v_4',$v_5);
exit
EOF


But when there is an error in the PL/SQL block, I need to error out shell script, which is running as a host concurrent program in Oracle, but it is not doing so.










share|improve this question
























  • if that block is normal shell code, then you need to use eval or run the script in a different manner — exec will substitute that shell with the call, so exit can never be reached. And to only exit on error, assuming plsql has sane exit codes, use || exit at the end of the call. It will still probably be moot, since it will only exit the current shell and you seem to want one more.
    – lynxlynxlynx
    Sep 30 '13 at 20:27










  • Just an FYI, when dealing with usernames/passwords with sqlplus you should be using Oracle Wallets: docs.oracle.com/cd/E25054_01/network.1111/e16543/…
    – slm
    Oct 1 '13 at 0:02













up vote
1
down vote

favorite









up vote
1
down vote

favorite











In the shell script, I am calling a PL/SQL stored procedure.



sqlplus -s <<EOF
$v_fcp_login
set head off feed off serverout on size 1000000
exec XXIRIS_TEST_K.XXIRIS_TEST('$v_1',$v_2,$v_3,'$v_4',$v_5);
exit
EOF


But when there is an error in the PL/SQL block, I need to error out shell script, which is running as a host concurrent program in Oracle, but it is not doing so.










share|improve this question















In the shell script, I am calling a PL/SQL stored procedure.



sqlplus -s <<EOF
$v_fcp_login
set head off feed off serverout on size 1000000
exec XXIRIS_TEST_K.XXIRIS_TEST('$v_1',$v_2,$v_3,'$v_4',$v_5);
exit
EOF


But when there is an error in the PL/SQL block, I need to error out shell script, which is running as a host concurrent program in Oracle, but it is not doing so.







shell-script ksh sql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 22:46









Rui F Ribeiro

38.2k1475125




38.2k1475125










asked Sep 30 '13 at 18:26









sam

2139




2139












  • if that block is normal shell code, then you need to use eval or run the script in a different manner — exec will substitute that shell with the call, so exit can never be reached. And to only exit on error, assuming plsql has sane exit codes, use || exit at the end of the call. It will still probably be moot, since it will only exit the current shell and you seem to want one more.
    – lynxlynxlynx
    Sep 30 '13 at 20:27










  • Just an FYI, when dealing with usernames/passwords with sqlplus you should be using Oracle Wallets: docs.oracle.com/cd/E25054_01/network.1111/e16543/…
    – slm
    Oct 1 '13 at 0:02


















  • if that block is normal shell code, then you need to use eval or run the script in a different manner — exec will substitute that shell with the call, so exit can never be reached. And to only exit on error, assuming plsql has sane exit codes, use || exit at the end of the call. It will still probably be moot, since it will only exit the current shell and you seem to want one more.
    – lynxlynxlynx
    Sep 30 '13 at 20:27










  • Just an FYI, when dealing with usernames/passwords with sqlplus you should be using Oracle Wallets: docs.oracle.com/cd/E25054_01/network.1111/e16543/…
    – slm
    Oct 1 '13 at 0:02
















if that block is normal shell code, then you need to use eval or run the script in a different manner — exec will substitute that shell with the call, so exit can never be reached. And to only exit on error, assuming plsql has sane exit codes, use || exit at the end of the call. It will still probably be moot, since it will only exit the current shell and you seem to want one more.
– lynxlynxlynx
Sep 30 '13 at 20:27




if that block is normal shell code, then you need to use eval or run the script in a different manner — exec will substitute that shell with the call, so exit can never be reached. And to only exit on error, assuming plsql has sane exit codes, use || exit at the end of the call. It will still probably be moot, since it will only exit the current shell and you seem to want one more.
– lynxlynxlynx
Sep 30 '13 at 20:27












Just an FYI, when dealing with usernames/passwords with sqlplus you should be using Oracle Wallets: docs.oracle.com/cd/E25054_01/network.1111/e16543/…
– slm
Oct 1 '13 at 0:02




Just an FYI, when dealing with usernames/passwords with sqlplus you should be using Oracle Wallets: docs.oracle.com/cd/E25054_01/network.1111/e16543/…
– slm
Oct 1 '13 at 0:02










1 Answer
1






active

oldest

votes

















up vote
1
down vote













First, you need to get SQL*Plus to error out if a SQL error occurs. You can do this by adding:



WHENEVER SQLERROR EXIT FAILURE


to your SQL script (probably up top). You can also give different codes (small non-negative integers; non-zero = failure) in place of the word FAILURE.



These will come back to your shell script in $?. So you can then have your shell script react to it. Altogether, it'd look something like this:



sqlplus -s <<EOF
$v_fcp_login
set head off feed off serverout on size 1000000
WHENEVER SQLERROR EXIT FAILURE
exec XXIRIS_TEST_K.XXIRIS_TEST('$v_1',$v_2,$v_3,'$v_4',$v_5);
exit
EOF
if [ 0 -ne "$?" ]; then
echo "Stored proc blew up." >&2
exit 1
fi


Of course, you can use different exit codes to indicate different things (e.g., if you were calling multiple stored procedures, you could exit 1 for the first one blowing up, exit 2 for the second, etc.)






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f93041%2ferror-out-shell-script-if-pl-sql-program-fails%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    First, you need to get SQL*Plus to error out if a SQL error occurs. You can do this by adding:



    WHENEVER SQLERROR EXIT FAILURE


    to your SQL script (probably up top). You can also give different codes (small non-negative integers; non-zero = failure) in place of the word FAILURE.



    These will come back to your shell script in $?. So you can then have your shell script react to it. Altogether, it'd look something like this:



    sqlplus -s <<EOF
    $v_fcp_login
    set head off feed off serverout on size 1000000
    WHENEVER SQLERROR EXIT FAILURE
    exec XXIRIS_TEST_K.XXIRIS_TEST('$v_1',$v_2,$v_3,'$v_4',$v_5);
    exit
    EOF
    if [ 0 -ne "$?" ]; then
    echo "Stored proc blew up." >&2
    exit 1
    fi


    Of course, you can use different exit codes to indicate different things (e.g., if you were calling multiple stored procedures, you could exit 1 for the first one blowing up, exit 2 for the second, etc.)






    share|improve this answer

























      up vote
      1
      down vote













      First, you need to get SQL*Plus to error out if a SQL error occurs. You can do this by adding:



      WHENEVER SQLERROR EXIT FAILURE


      to your SQL script (probably up top). You can also give different codes (small non-negative integers; non-zero = failure) in place of the word FAILURE.



      These will come back to your shell script in $?. So you can then have your shell script react to it. Altogether, it'd look something like this:



      sqlplus -s <<EOF
      $v_fcp_login
      set head off feed off serverout on size 1000000
      WHENEVER SQLERROR EXIT FAILURE
      exec XXIRIS_TEST_K.XXIRIS_TEST('$v_1',$v_2,$v_3,'$v_4',$v_5);
      exit
      EOF
      if [ 0 -ne "$?" ]; then
      echo "Stored proc blew up." >&2
      exit 1
      fi


      Of course, you can use different exit codes to indicate different things (e.g., if you were calling multiple stored procedures, you could exit 1 for the first one blowing up, exit 2 for the second, etc.)






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        First, you need to get SQL*Plus to error out if a SQL error occurs. You can do this by adding:



        WHENEVER SQLERROR EXIT FAILURE


        to your SQL script (probably up top). You can also give different codes (small non-negative integers; non-zero = failure) in place of the word FAILURE.



        These will come back to your shell script in $?. So you can then have your shell script react to it. Altogether, it'd look something like this:



        sqlplus -s <<EOF
        $v_fcp_login
        set head off feed off serverout on size 1000000
        WHENEVER SQLERROR EXIT FAILURE
        exec XXIRIS_TEST_K.XXIRIS_TEST('$v_1',$v_2,$v_3,'$v_4',$v_5);
        exit
        EOF
        if [ 0 -ne "$?" ]; then
        echo "Stored proc blew up." >&2
        exit 1
        fi


        Of course, you can use different exit codes to indicate different things (e.g., if you were calling multiple stored procedures, you could exit 1 for the first one blowing up, exit 2 for the second, etc.)






        share|improve this answer












        First, you need to get SQL*Plus to error out if a SQL error occurs. You can do this by adding:



        WHENEVER SQLERROR EXIT FAILURE


        to your SQL script (probably up top). You can also give different codes (small non-negative integers; non-zero = failure) in place of the word FAILURE.



        These will come back to your shell script in $?. So you can then have your shell script react to it. Altogether, it'd look something like this:



        sqlplus -s <<EOF
        $v_fcp_login
        set head off feed off serverout on size 1000000
        WHENEVER SQLERROR EXIT FAILURE
        exec XXIRIS_TEST_K.XXIRIS_TEST('$v_1',$v_2,$v_3,'$v_4',$v_5);
        exit
        EOF
        if [ 0 -ne "$?" ]; then
        echo "Stored proc blew up." >&2
        exit 1
        fi


        Of course, you can use different exit codes to indicate different things (e.g., if you were calling multiple stored procedures, you could exit 1 for the first one blowing up, exit 2 for the second, etc.)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 30 '13 at 20:49









        derobert

        71k8151210




        71k8151210






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f93041%2ferror-out-shell-script-if-pl-sql-program-fails%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Morgemoulin

            Scott Moir

            Souastre