初学oracle,对于异常处理,我目前使用如下两种:
1.通过dbms_output.put_line来进行后台输出,但是这种情况有的时候对于用户不是很友好,因为他们看不到。~~
2.通过设置raise_application_error来设置自定义的异常处理,这种例外处理方式在报错的时候会以窗口的形式体现
代码段:
declare
/*创建一个 异常变量 e_error_information*/
e_error_information exception;
p_number number := &p_number;
begin
if p_number >= 0 then
/*通过raise_application_error提示框来处理异常*/
raise_application_error(-20001, 'the number bigger than 0');
elsif p_number < 0 then
/*相当于实例化e_error_information这个异常变量,即初始化*/
raise e_error_information;
end if;
exception
when e_error_information then
/*当异常为 e_error_information时,输出错误提示*/
dbms_output.put_line('the number less than 0');
end;
在上述代码中,分别列举了这两种异常处理方式:
1.raise_application_error(-20001, 'the number bigger than 0');
对于第一种异常 报错如下:
这里红框处就是刚才添加的异常处理的提示信息
2. raise e_error_information;
对于第二种异常处理,报错是输出的形式,如下:
就是输出字符串信息
还有一些其他的处理方法,这里就不举例了 ,这个作为笔记使用!