What does the SQLCODE Function do?
The SQLCODE function returns the error number 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 SQLCODE 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;
本文深入探讨了SQLCODE函数的功能及其在代码中处理错误的方式,包括如何使用该函数来记录错误代码和消息,以及如何在遇到未预见错误时通过SQLCODE函数进行错误处理。

660

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



