0% found this document useful (0 votes)
338 views5 pages

Exceptions in Oracle

This document discusses exceptions in Oracle. It explains that errors thrown from an execution block are caught first by any local exception block and then by any containing block. It provides the syntax for handling exceptions using WHEN clauses. It also describes the Oracle built-in functions SQLCODE and SQLERRM that return error codes and messages for predefined and user-defined exceptions. An example demonstrates catching a VALUE_ERROR exception.

Uploaded by

Mainak De
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
338 views5 pages

Exceptions in Oracle

This document discusses exceptions in Oracle. It explains that errors thrown from an execution block are caught first by any local exception block and then by any containing block. It provides the syntax for handling exceptions using WHEN clauses. It also describes the Oracle built-in functions SQLCODE and SQLERRM that return error codes and messages for predefined and user-defined exceptions. An example demonstrates catching a VALUE_ERROR exception.

Uploaded by

Mainak De
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

EXCEPTIONS IN ORACLE

Run-time errors can happen in declaration, execution, and exception PL/SQL blocks. The easiest to catch and handle are those errors thrown from an execution block because they are caught first by any local exception block and next by any containing block.
Syntax: WHEN {predefined_exception | user_defined_exception | OTHERS} THEN exception_handling_statement; [RETURN | EXIT ];

Oracle Exception Management Built-in Functions


Function SQLCODE Oracle-Predefined Errors Returns a negative number that maps to the Oracle predefined exceptions but for one special case: the NO_ DATA_FOUND exception returns a positive 100. User-Defined Errors Returns a positive 1 if there is no EXCEPTION_INIT PRAGMA defined. If an EXCEPTION_INIT PRAGMA is defined, it returns a valid number in the range of negative 20001 to negative 20999.

Function
SQLERRM

Oracle-Predefined Errors
Returns the defined error code and message for a raised exception if no number is passed to it.

User-Defined Errors

Returns a 1 and a UserDefined Exception message if triggered Returns the actual number parameter by the RAISE command. as a negative integer and a nonReturns Oracle exception message if a positive a valid integer in the range of number is passed to it or a negative negative 20001 to negative number that is not a predefined Oracle 20999 exception. and a text message set by the RAISE_APPLICATION_INFO Returns the actual number parameter function. as a negative integer and the Oracle defined message if a negative number for an Oracle-predefined exception is passed.

EXAMPLE
DECLARE a VARCHAR2(1); b VARCHAR2(2) := 'AB'; BEGIN a := b; EXCEPTION WHEN value_error THEN dbms_output.put_line('You can''t put ['||b||'] in a one character string.'); END; /

You might also like