源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

详解Oracle自定义异常示例

  • 时间:2021-07-12 01:49 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:详解Oracle自定义异常示例
[b]1.弹出错误框: [/b] 示例代码:
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; 
执行结果: [img]http://files.jb51.net/file_images/article/201604/201604061119375.png[/img] [b]2.控制台显示:[/b] 示例代码:
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;
执行结果: [img]http://files.jb51.net/file_images/article/201604/201604061119376.png[/img] [b]PS:ORACLE 用户自定义异常小例子 [/b]
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)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部