Sql*plus always returns exit code 0?

后端 未结 3 1363
梦毁少年i
梦毁少年i 2020-11-29 11:06

Whenever I run a sql script using Sql*plus and check for $?, I get 0 even when the script wasn\'t succesful.

Example

#$ sqlplus user/password@instanc         


        
3条回答
  •  佛祖请我去吃肉
    2020-11-29 11:41

    You have to explicitly tell sqlplus to do that, in your script. Basically, there are two statements that you can use:

    • WHENEVER SQLERROR EXIT SQL.SQLCODE
    • WHENEVER OSERROR EXIT

    For example:

    WHENEVER SQLERROR EXIT SQL.SQLCODE
    begin
      SELECT COLUMN_DOES_NOT_EXIST FROM DUAL;
    END;
    /
    

    And for OS errors:

    WHENEVER OSERROR EXIT FAILURE
    START no_such_file
    

    For more information, see this and that.

    Hope it helps. Good Luck!

提交回复
热议问题