In Oracle PL/SQL, the RAISE statement is used to explicitly raise an exception within a PL/SQL block. It immediately stops normal execution of a PL/SQL block or subprogram and transfers control to an exception handler. It can be used to raise both system defined and user defined exceptions.
If an exception is raised and PL/SQL cannot find a handler for it in the current block, the exception then propagates to successive enclosing blocks, until a handler is found or there are no more blocks to propagate to. If no handler is found, PL/SQL returns an unhandled exception error to the host environment.
RAISE [EXCEPTION NAME]
The PL/SQL block below selects an employee corresponding to a given employee IDd. If no employee record is found it raises the NO_DATA_FOUND exception and displays a message. Note that NO_DATA_FOUND is a system defined exception.
CURSOR C IS
WHERE EMPNO = 300;
FETCH C INTO L_EMP;
IF L_EMP IS NULL THEN
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No Employee exists for this employee ID.');
No Employee exists for this employee ID.
PL/SQL procedure successfully completed.