What are SQLCODE and SQLERRM



What are SQLCODE and SQLERRM


--====================================================
SQLCODE returns the number of the last encountered error.
SQLERRM returns the  message associated with its error-number argument.

Exception Name                      Error Code (SQLCODE)        ERROR Description (SQLERRM)
INVALID_NUMBER                       -1722                                  ORA-01722: invalid number  
NO_DATA_FOUND                      -1403                                   ORA-01403: no data found
TOO_MANY_ROWS                    -1422                                   ORA-01422: exact fetch returns more than requested number of rows
VALUE_ERROR                          -6502                                    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
VALUE_ERROR                          -6502                                    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ZERO_DIVIDE                           -1476                                     ORA-01476: divisor is equal to zero

--====================================================

--============
Example:-1
Named Exception
--============

declare
V_name Scott.emp.ename%type;
 
begin

    SELECT ENAME
    INTO V_NAME
    FROM SCOTT.EMP;


EXCEPTION
WHEN TOO_MANY_ROWS THEN
dbms_output.put_line('SQLCODE: '|| SQLCODE);
dbms_output.put_line('SQLERRM: '|| SQLERRM);

end;


OUTPUT:-
SQLCODE: -1422
SQLERRM: ORA-01422: exact fetch returns more than requested number of rows


--============
Example:-2
Un-Named Exception
--============

DECLARE
LARGE_VALUE  exception;
PRAGMA EXCEPTION_INIT(LARGE_VALUE, -1438);
BEGIN

INSERT INTO SCOTT.emp  (EMPNO) VALUES (123432123312);

EXCEPTION
WHEN LARGE_VALUE THEN
dbms_output.put_line('SQLCODE: '|| SQLCODE);
dbms_output.put_line('SQLERRM: '|| SQLERRM);
END;


OUTPUT:-
SQLCODE: -1438
SQLERRM: ORA-01438: value larger than specified precision allowed for this column


--============
Example:-3
User Defined Exception
--============

DECLARE
V_Total_Qty   NUMBER := 100;
V_Count_Of_Person  NUMBER := 0;
V_Per_distrib_Qty      NUMBER;
 
BEGIN

If  V_Count_Of_Person = 0 THEN
RAISE_APPLICATION_ERROR (-20008, 'you can not devied with Zero please check..');

ELSE
  V_Per_distrib_Qty := V_Total_Qty / V_Count_Of_Person; 
END IF;

EXCEPTION WHEN OTHERS THEN
dbms_output.put_line('SQLCODE: '|| SQLCODE);
dbms_output.put_line('SQLERRM: '|| SQLERRM);

END;

OUTPUT:-
SQLCODE: -20008
SQLERRM: ORA-20008: you can not devied with Zero please check..


Comments

Popular posts from this blog

E-Text Report In Fusion | Types of E-Text reports

Supplier API's

How to pass default Parameter in cursor