PL/SQL异常获取

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匹配多行

 SET SERVEROUTPUT ON
DECLARE pename EMP.ENAME % TYPE ;
BEGIN
SELECT
ename INTO pename
FROM
emp
WHERE
deptno = 10 ; EXCEPTION
WHEN too_many_rows THEN
dbms_output.put_line (
'select inti 匹配了多行'
) ;
WHEN others THEN
dbms_output.put_line ('其他例外') ;
END ;
/

3.zero_divide

 SET SERVEROUTPUT ON
DECLARE pnum NUMBER ;
BEGIN
pnum := 1 / 0 ; EXCEPTION
WHEN zero_divide THEN
DBMS_OUTPUT.PUT_LINE ('1/0 不能做除数') ; dbms_output.put_line ('零不能做除数') ;
WHEN others THEN
dbms_output.put_line ('其他错误') ;
END ;
/

4.VALUE_ERROR

 SET SERVEROUTPUT ON
DECLARE pnum NUMBER ;
BEGIN
pnum := 'abc' ; EXCEPTION
WHEN VALUE_ERROR THEN
DBMS_OUTPUT.PUT_LINE ('字符转换错误') ;
WHEN others THEN
dbms_output.put_line ('其他错误') ;
END ;
/
上一篇:mysql概要(六)连接


下一篇:centos 安装php