Han*_*ank 3 oracle logging ksh plsql sqlplus
在 sqlplus 中执行时,需要一种将 PL/SQL 程序错误消息重定向到日志文件的方法。
假设 PL/SQL 程序被命名send_2012.sql
并且它有以下异常块
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;
Run Code Online (Sandbox Code Playgroud)
要在 KornShell (ksh) 脚本中运行 PL/SQL 程序,我有:
sqlplus some_username/'some_password' @some_database \
@/some/directory/send_2012.sql \
$parameter1 $paramenter2
Run Code Online (Sandbox Code Playgroud)
假设执行时发生错误send_2012.sql
,如何将错误消息从 var_err 重定向到/some/log/directory/log_send_2012.txt
?
非常感激。
像这样设置你的脚本:
-- 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
Run Code Online (Sandbox Code Playgroud)
从该目录登录 sqlplus 并运行:
SQL>@test.sql
Run Code Online (Sandbox Code Playgroud)
您将在日志文件 (test.log) 中找到异常。
归档时间: |
|
查看次数: |
16190 次 |
最近记录: |