In Oracle, you can use "DBMS_OUTPUT" with the "put_line" printing method to obtain stored procedure exception information. The syntax is "DBMS_OUTPUT.put_line('sqlerrm : ' ||sqlerrm);"; "put_line" printing method Used for line break output, sqlcode represents the exception number, sqlerrm represents the detailed information of the exception, and can be used with the substr() method to intercept exception information.
The operating environment of this tutorial: Windows 10 system, Oracle version 12c, Dell G3 computer.
Display of Oracle stored procedure exception information
When writing stored procedures before, the exception handling method was:
In this way of writing, when the stored procedure throws an exception, we don’t know what kind of exception it threw (for example, the column width is not large enough and an exception is thrown when inserting data). The exception can be displayed as follows Information
EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.put_line('sqlcode : ' ||sqlcode); DBMS_OUTPUT.put_line('sqlerrm : ' ||sqlerrm); ROLLBACK; END ...
sqlcode is the exception number, sqlerrm is the detailed information of the exception. If there is too much exception information, you can intercept a section for display. For example,
DBMS_OUTPUT.put_line('sqlerrm : ' ||substr(sqlerrm,1,100));
is to intercept the first 100 characters and display it.
Recommended tutorial: "Oracle Video Tutorial"
The above is the detailed content of How to obtain process exception information in Oracle. For more information, please follow other related articles on the PHP Chinese website!