Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Faça com que a compilação de marionete falhe quando o script SQL contido falhar na execução


Acredito que o puppet detecta o sucesso do script com base no código de retorno do programa chamado. Por padrão, o sqlplus retorna 0 quando você o fecha, independentemente do que possa ter sido executado durante a sessão.
[[email protected] ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Apr 17 08:47:08 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select asdjkhasd from sadbjaksd;
select asdjkhasd from sadbjaksd
                      *
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> quit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[[email protected] ~]$ echo $?
0

Se você quiser que o sqlplus saia com um status de erro, você pode usar o comando always, por exemplo.
[[email protected] ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.3.0 Production on Thu Apr 17 08:48:17 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> whenever sqlerror exit failure;
SQL> select bogus from nowhere;
select bogus from nowhere
                  *
ERROR at line 1:
ORA-00942: table or view does not exist


Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[[email protected] ~]$ echo $?
1

Observe o código de retorno diferente no último caso. Isso deve ser suficiente para que o fantoche saiba que o comando falhou.