Different Values of SQLCODE and SQLERRM : Exception Handle « PL SQL « Oracle PL / SQL






Different Values of SQLCODE and SQLERRM

     
SQL>
SQL> CREATE TABLE myLogTable (
  2    code             NUMBER,
  3    message          VARCHAR2(200),
  4    info             VARCHAR2(100)
  5    );

Table created.

SQL>
SQL>
SQL> DECLARE
  2    v_ErrorText   myLogTable.message%TYPE;
  3  BEGIN
  4    /* SQLERRM(0) */
  5    v_ErrorText := SUBSTR(SQLERRM(0), 1, 200);
  6    INSERT INTO myLogTable (code, message, info)
  7      VALUES (0, v_ErrorText, 'SQLERRM(0)');
  8
  9    /* SQLERRM(100) */
 10    v_ErrorText := SUBSTR(SQLERRM(100), 1, 200);
 11    INSERT INTO myLogTable (code, message, info)
 12      VALUES (100, v_ErrorText, 'SQLERRM(100)');
 13
 14    /* SQLERRM(10) */
 15    v_ErrorText := SUBSTR(SQLERRM(10), 1, 200);
 16    INSERT INTO myLogTable (code, message, info)
 17      VALUES (10, v_ErrorText, 'SQLERRM(10)');
 18
 19    /* SQLERRM with no argument */
 20    v_ErrorText := SUBSTR(SQLERRM, 1, 200);
 21    INSERT INTO myLogTable (code, message, info)
 22      VALUES (NULL, v_ErrorText, 'SQLERRM with no argument');
 23
 24    /* SQLERRM(-1) */
 25    v_ErrorText := SUBSTR(SQLERRM(-1), 1, 200);
 26    INSERT INTO myLogTable (code, message, info)
 27      VALUES (-1, v_ErrorText, 'SQLERRM(-1)');
 28
 29    /* SQLERRM(-54) */
 30    v_ErrorText := SUBSTR(SQLERRM(-54), 1, 200);
 31    INSERT INTO myLogTable (code, message, info)
 32      VALUES (-54, v_ErrorText, 'SQLERRM(-54)');
 33
 34  END;
 35  /

PL/SQL procedure successfully completed.

SQL>
SQL> select * from myLogTable;

      CODE MESSAGE
---------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
INFO
----------------------------------------------------------------------------------------------------
         0 ORA-0000: normal, successful completion
SQLERRM(0)

       100 ORA-01403: no data found
SQLERRM(100)

        10  -10: non-ORACLE exception
SQLERRM(10)


      CODE MESSAGE
---------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
INFO
----------------------------------------------------------------------------------------------------
           ORA-0000: normal, successful completion
SQLERRM with no argument

        -1 ORA-00001: unique constraint (.) violated
SQLERRM(-1)

       -54 ORA-00054: resource busy and acquire with NOWAIT specified
SQLERRM(-54)


6 rows selected.

SQL>
SQL> drop table myLogTable;

Table dropped.

SQL>

   
    
    
    
  








Related examples in the same category

1.Check exception type
2.Deal with multiple exception branches
3.when other exceptions then
4.Handle update exception
5.declaration exception
6.handle exception of duplicate value on index
7.when other then not user-defined exception
8.Using PRAGMA EXCEPTION_INIT
9.The OTHERS Exception Handler
10.Error-handling features of PL/SQL: log exception
11.PLS-483 error: Duplicate Handlers
12.NO_DATA_FOUND exception.
13.The scope of exceptions.
14.Sub block in exception section
15.Catch all exceptions
16.Catch user-defined exception
17.Check zero divide exception
18.Combines declaring an EXCEPTION variable
19.Insert error message to a table in exception handler
20.Mapping a user-defined error code to an EXCEPTION variable
21.This script demonstrates the EXCEPTION_INIT pragma.
22.Error Handling Call
23.Raise exception in if statement