1.no_data
SET SERVEROUTPUT ON DECLARE pename EMP.ENAME % TYPE ; BEGIN SELECT ename INTO pename FROM emp WHERE empno = 1234 ; EXCEPTION WHEN no_data_found THEN dbms_output.put_line ('没有找到该员工') ; WHEN others THEN dbms_output.put_line ('其他例外未知') ; END ; /
2.too_many_rows匹配多行
1 SET SERVEROUTPUT ON 2 DECLARE pename EMP.ENAME % TYPE ; 3 BEGIN 4 SELECT 5 ename INTO pename 6 FROM 7 emp 8 WHERE 9 deptno = 10 ; EXCEPTION 10 WHEN too_many_rows THEN 11 dbms_output.put_line ( 12 'select inti 匹配了多行' 13 ) ; 14 WHEN others THEN 15 dbms_output.put_line ('其他例外') ; 16 END ; 17 /
3.zero_divide
1 SET SERVEROUTPUT ON 2 DECLARE pnum NUMBER ; 3 BEGIN 4 pnum := 1 / 0 ; EXCEPTION 5 WHEN zero_divide THEN 6 DBMS_OUTPUT.PUT_LINE ('1/0 不能做除数') ; dbms_output.put_line ('零不能做除数') ; 7 WHEN others THEN 8 dbms_output.put_line ('其他错误') ; 9 END ; 10 /
4.VALUE_ERROR
1 SET SERVEROUTPUT ON 2 DECLARE pnum NUMBER ; 3 BEGIN 4 pnum := 'abc' ; EXCEPTION 5 WHEN VALUE_ERROR THEN 6 DBMS_OUTPUT.PUT_LINE ('字符转换错误') ; 7 WHEN others THEN 8 dbms_output.put_line ('其他错误') ; 9 END ; 10 /