PL/SQL RAISE_APPLICATION_ERROR

Published on by LakshmiSaahul,Dhana Royal

PL/SQL RAISE_APPLICATION_ERROR
In PL/SQL RAISE_APPLICATION_ERROR function use to assign exception name and exception error code. Define RAISE_APPLICATION_ERROR function syntax,
raise_application_error(error_number, error_message);
Example Code
raise_app_error.sql
SQL>edit user-named_exp
DECLARE
myex EXCEPTION;
n NUMBER := &n;
BEGIN
FOR i IN 1..n LOOP
dbms_output.put.line(i);
IF i=n THEN
RAISE myex;
END IF;
END LOOP;
EXCEPTION
WHEN myex THEN
RAISE_APPLICATION_ERROR(-20015, 'loop finish');
END;
/

When RAISE_APPLICATION_ERROR execute it's return error message and error code looking same as oracle built-in error.

Advertising
To be informed of the latest articles, subscribe:
Comment on this post