title: How to exit sqlplus when error happens
body: <p>I would like to catch any sql error that could happen so I wrote this in the ksh :</p>
  
  <pre><code>$ORACLE_HOME/bin/sqlplus -s u/p &lt;&lt;EOF
      WHENEVER OSERROR EXIT 68;
      WHENEVER SQLERROR EXIT SQL.SQLCODE;
  
      CREATE TABLE new_table
      AS (SELECT * FROM wrong_old_table);
      COMMIT;
  EOF
  </code></pre>
  
  <p>I put a wrong name for the old table to see what happens. I expect to have the sqlcode only like I ask in WHENEVER SQLERROR but I have this :</p>
  
  <pre><code> AS (SELECT * FROM wrong_old_table)
                        *
   ERROR at line 2:
   ORA-00942: table or view does not exist
  </code></pre>
  
  <p>I changed the code :</p>
  
  <pre><code> $ORACLE_HOME/bin/sqlplus -s u/p &lt;&lt;EOF
      WHENEVER OSERROR EXIT 68;
      WHENEVER SQLERROR EXIT SQL.SQLCODE;
  
      BEGIN
         CREATE TABLE new_table
         AS (SELECT * FROM wrong_old_table);
         COMMIT;
      END;
   EOF
  
   sql_code=$?
  
   echo "code=$sql_code"
  </code></pre>
  
  <p>Even though there is an error, the code equals 0. Where is the sql error code ?</p>
  
  <hr>
  
  <p>In fact, no use of begin...end and it works</p>