--Pre-defined exception: The system has declared an exception
DECLARE
V_name EMP. Ename%type;
BEGIN
SELECT ename to V_name from EMP WHERE EMPNO = 1234;
EXCEPTION
When No_data_found Then
Dbms_output. Put_Line (' No data found ');
When OTHERS Then
Dbms_output.put_line (' other anomalies ');
END;
--Non-predefined exception: System exception, the system does not declare it
DECLARE
E_fkexception EXCEPTION;
PRAGMA Exception_init (e_fkexception,-2291);
BEGIN
INSERT into EMP VALUES (8888, ' Tom ', ' Clerk ', 7902,sysdate,1900,null,50);
EXCEPTION
When E_fkexception Then
Dbms_output.put_line (' foreign key exception! ');
When OTHERS Then
Dbms_output.put_line (' other anomalies ');
END;
--User-defined exception
DECLARE
E_salexception EXCEPTION;
V_sal Emp.sal%type;
V_empno Emp.empno%type: = &no;
BEGIN
SELECT sal into v_sal from emp WHERE empno = v_empno;
IF V_sal <
RAISE e_salexception;
END IF;
EXCEPTION
When E_salexception Then
Dbms_output.put_line (' wages cannot be less than 1000! ');
END;
Exception classification and its processing in PL/SQL language programming