Internally Defined Exception
It is type of exception that are predefined by the PL/SQL runtime environment to handle common error conditions which occur during program execution. It includes exception such as NO_DATA_FOUND, TOO_MANY_ROWS, ZERO_DIVIDE, DUP_VAL_ON_INDEX, STORAGE_ERROR etc.
Example:
DECLARE
result NUMBER;
BEGIN
-- Some computation that might cause an internally defined exception
result := 10 / 0; -- This will raise ZERO_DIVIDE exception
EXCEPTION
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE('Cannot divide by zero!');
END;
Output:
Statement processed.
Cannot divide by zero!
Explanation: In the above query we computes a division operation (10 / 0
) which causes a division by zero error and leading to the ZERO_DIVIDE
exception being raised. The EXCEPTION
block catches and handles this exception by printing ‘Cannot divide by zero!‘ using DBMS_OUTPUT
.
PUT_LINE
.
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