Current Exception
It is a type of exception that is currently being handled in the PL/SQL block. It is useful in nested blocks where an exception might be raised in an inner block and you want to reference that specific exception in an outer block. SQLERRM function is used to refer current exception.
Example:
DECLARE
custom_exception EXCEPTION;
BEGIN
BEGIN
-- Some operation that might raise an exception
RAISE custom_exception;
EXCEPTION
WHEN OTHERS THEN
-- Handle the exception and reference the current exception
DBMS_OUTPUT.PUT_LINE('Exception handled: ' || SQLERRM);
END;
END;
Output:
Statement processed.
Exception handled: User-Defined Exception
Explanation: In the above query we demonstrates nested exception handling. It raises a user-defined exception (custom_exception
) within an inner block. The EXCEPTION
block in the outer block catches any exceptions (including the custom_exception
) using WHEN OTHERS
and prints the error message (SQLERRM
) to the console.
PL/SQL RAISE Exceptions
PL/SQL stands for Procedural Language Extension to the Structured Query Language and it is designed specifically for Oracle databases. It extends Structured Query Language (SQL) capabilities by allowing the creation of stored procedures, functions, and triggers. It is a block-structured language that combines SQL with the procedural features of programming languages. In this article, we will learn about RAISE Exception in PL/SQL with its syntax, types, and examples.
Contact Us