Posted on Sunday, 6th September 2009 by captainmi2

RAISE_APPLICATION_ERROR is used to create a user defined error messages.
The user defined messages are associated with the user defined number (SQLCODE) using RAISE_APPLICATION_ERROR.

DECLARE
a NUMBER := 0;
b NUMBER := 10;
BEGIN
IF (a = 0) THEN
RAISE_APPLICATION_ERROR(-20000,’ Cannot Divide by Zero’);
ELSE
b:= b/a;
dbms_output.put_line(to_char(b));
END IF;
END;

this will output
ORA-20000: Cannot Divide by Zero

Tags:
Posted in Intermediate, Oracle | Comments (0)