发布于 2016-05-12 09:57:45 | 124 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Oracle关系数据库管理系统

Oracle Database,又名Oracle RDBMS,或简称Oracle。是甲骨文公司的一款关系数据库管理系统。到目前仍在数据库市场上占有主要份额。


这篇文章主要介绍了详解Oracle自定义异常示例的相关资料,需要的朋友可以参考下

1.弹出错误框:

示例代码:


declare 
v_count number;
begin 
select count(*) into v_count from dept;
if v_count < 10 then 
raise_application_error(-20001,'数量小于10');
end if;
end; 

执行结果:

2.控制台显示:

示例代码:


declare 
v_count number;
my_exp exception;
begin 
select count(*) into v_count from dept;
if v_count < 10 then 
raise my_exp;
end if;
exception 
when my_exp then 
dbms_output.put_line('数量小于10');
when others then 
dbms_output.put_line('其他异常');
end;

执行结果:

PS:ORACLE 用户自定义异常小例子


CREATE OR REPLACE PROCEDURE test_Exception_byLeejin
(
ParameterA IN varchar,
ParameterB IN varchar,
ErrorCode OUT varchar --返回值,错误编码
)
AS
/*以下是一些变量的定义*/
V NUMBER;
V nvarchar();
V NUMBER; 
APP_EXP EXCEPTION; --自定义异常
BEGIN
ErrorCode :='';
IF (ParameterA=ParameterB) THEN
ErrorCode := 'ParameterA = ParameterB';
RAISE APP_EXP; -- 抛出异常
END IF;
EXCEPTION
WHEN APP_EXP THEN --在处理异常
RAISE_APPLICATION_ERROR(-,ErrorCode);
WHEN OTHERS THEN 
RAISE_APPLICATION_ERROR(-,'未知异常');
END;



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务