What does the SQLERRM Function do?
The SQLERRM function returns the error message associated with the most recently raised error exception. This function should only be used within the Exception Handling section of your code:
EXCEPTION
WHEN exception_name1 THEN
[statements]WHEN exception_name2 THEN
[statements]WHEN exception_name_n THEN
[statements]WHEN OTHERS THEN
[statements]END [procedure_name];
You could use the SQLERRM function to raise an error as follows:
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
END;
Or you could log the error to a table as follows:
EXCEPTION
WHEN OTHERS THEN
err_code := SQLCODE;
err_msg := substr(SQLERRM, 1, 200);INSERT INTO audit_table (error_number, error_message)
VALUES (err_code, err_msg);
END;
本文详细介绍了SQLERRM函数的功能及使用方法。该函数用于返回最近触发错误的错误消息,并通常应用于异常处理部分。文中提供了如何使用SQLERRM来记录错误信息到表中的示例。

3772

被折叠的 条评论
为什么被折叠?



