Monday, October 4, 2010

Raise Application Error

RAISE_APPLICATION_ERROR procdure defined in STANDARD package and it can only invoked from stored subprogram.This procedure is used to raise a error code and error message

      RAISE_APPLICATION_ERROR(error_code, message [,{TRUE|FALSE}]);

If TRUE specified, PL/SQL put error_code on the top of the error stack otherwise error stack replaced with the error_code

CREATE PROCEDURE training_status ( l_training_id VARCHAR2(10)) IS
   v_no_of_student NUMBER(3);
BEGIN
   SELECT COUNT(1) INTO V_no_of_student
         FROM training
         WHERE training_id = l_training_id;


    IF v_no_of_student >= 40 THEN --explicitly raise error
           RAISE_APPLICATION_ERROR(-20000,'Training class full');
    END IF;
END;
/

DECLARE
   e_trainign_full EXCEPTION;  --declare exception
   PRAGMA EXCEPTION_INIT e_trainign_full(-20000,e_class_full);
BEGIN
    training_status('ORACLE');
EXCEPTION
   WHEN e_trainign_full THEN
   DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQLERRM(-20000)));
END;
/

Result:
    ORA-20000: Training Class full

No comments:

Post a Comment

External Table

Oracle External Table External tables are defined as tables that do not resides in the database allows you to access data that is stor...