title: redirect plsql error message to a log file when executing it in sqlplus
body: <p>Need a way to redirect PL/SQL program error message to a log file when executing it in sqlplus. </p>
  
  <p>Say the PL/SQL program is named <code>send_2012.sql</code> and it has the following exception block</p>
  
  <pre><code>EXCEPTION
          WHEN NO_DATA_FOUND
          THEN
                  var_err := 'Data not found. ';
          WHEN OTHERS
          THEN
                  var_err := 'Error in '
                          || $$plsql_unit
                          || ' | '
                          || SQLERRM
                          || ' | '
                          || 'Details: '
                          || DBMS_UTILITY.format_error_backtrace;
  END;
  </code></pre>
  
  <p>To run the PL/SQL program in a KornShell (ksh) script,  I have:</p>
  
  <pre><code>sqlplus some_username/'some_password' @some_database \
              @/some/directory/send_2012.sql \
              $parameter1 $paramenter2
  </code></pre>
  
  <p>Suppose error occurs when executing <code>send_2012.sql</code>, how can I redirect the error message from var_err to <code>/some/log/directory/log_send_2012.txt</code>?</p>
  
  <p>Much appreciated.</p>