Home > Database > Oracle > body text

How to obtain process exception information in Oracle

WBOY
Release: 2022-06-10 10:15:37
Original
3241 people have browsed it

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.

How to obtain process exception information in Oracle

The operating environment of this tutorial: Windows 10 system, Oracle version 12c, Dell G3 computer.

How to obtain process exception information in Oracle

Display of Oracle stored procedure exception information

When writing stored procedures before, the exception handling method was:

How to obtain process exception information in Oracle

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 ...
Copy after login

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));
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template