当前位置: 移动技术网 > IT编程>数据库>Oracle > 详解Oracle自定义异常示例

详解Oracle自定义异常示例

2017年12月08日  | 移动技术网IT编程  | 我要评论

男人之苦粤语,现代冥帝传,赵静沛

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;

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网