redirect plsql error message to a log file when executing it in sqlplus

喜欢而已 提交于 2019-12-05 21:37:55

Setup your script like this:

-- test.sql script run from sqlplus
set serveroutput on
set echo on
WHENEVER SQLERROR EXIT SQL.SQLCODE
spool on
spool test.log

declare
  l_val date;
begin
  select sysdate into l_val from dual where 1=0;
exception
  when others then raise;
end;
/

spool off

log into sqlplus from that directory and run:

SQL>@test.sql

You'll find the exceptions in the log file (test.log).

I worked around the logging issue, here is what I did:

Within the pl/sql program I inserted DBMS_PUTLINE("error messages goes here, etc"); to both the program body and exception sections.

When calling sqlplus from a Korn shell script, I used a regular output redirect to log pl/sql exceptions:

sqlplus some_username/'some_password' @some_database \
            @/some/directory/send_2012.sql \
            $parameter1 $paramenter2 \
            > /some/log/directory/send_2012.log

What I did may not be the best solution. Wrap Spool before and after your pl/sql program may give you more options on formatting, but it may also include the output result (say from the select statement) when system executes the program successfully.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!