Mega Code Archive

 
Categories / Oracle PLSQL Tutorial / PL SQL Programming
 

Using SQLCODE for error code and SQLERRM for error message

SQL> SQL> DECLARE   2    e_TooManyEmployee EXCEPTION;  -- Exception to indicate an error condition   3    v_ErrorCode NUMBER;           -- Variable to hold the error message code   4    v_ErrorText VARCHAR2(200);    -- Variable to hold the error message text   5   6  BEGIN   7    RAISE e_TooManyEmployee;   8  EXCEPTION   9    WHEN e_TooManyEmployee THEN  10      DBMS_OUTPUT.put_line('e_TooManyEmployee');  11      DBMS_OUTPUT.put_line(v_ErrorCode);  12      DBMS_OUTPUT.put_line(v_ErrorText);  13  14    WHEN OTHERS THEN  15      v_ErrorCode := SQLCODE;  16      v_ErrorText := SUBSTR(SQLERRM, 1, 200);  -- Note the use of SUBSTR here.  17  END;  18  / e_TooManyEmployee PL/SQL procedure successfully completed. SQL>