Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 The Oracle PL/SQL RAISE Statement      [Return To Index] Jump to:  
  Looking for the original pages? (formerly called "Morgan's Library") You can find them here.

Term: RAISE

Definition:
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.

Example Syntax:

RAISE [EXCEPTION NAME]


Example Usage:

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.

DECLARE
L_EMP VARCHAR2(1000);
CURSOR C IS
SELECT ENAME
FROM EMPLOYEE
WHERE EMPNO = 300;
BEGIN
OPEN C;
FETCH C INTO L_EMP;
CLOSE
C;
IF L_EMP IS NULL THEN
RAISE NO_DATA_FOUND;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No Employee exists for this employee ID.');
END;

No Employee exists for this employee ID.

PL/SQL procedure successfully completed.



Related Links:
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 208 users online    © 2009 psoug.org
PSOUG LOGIN
Username: 
Password: 
Forgot your password?