数据库-异常处理

—处理步骤
declare
–声明变量
begin
–处理逻辑
exception
–处理异常
when 异常1 then
。。。
when 异常2 then
。。。
when others then
。。。处理其他异常
end;

–常见异常
zero_divide : 除零异常
value_error : 类型转换异常
too_many_row : 查询多行数据,但是赋值给了rowtype
no_data_found : 没有找到数据
— 例:
declare
vi number;
vrow emp%rowtype;
bagein
vi = ‘aaa’; --类型转换异常
vi := 8/0; --除零异常
select * into vrow from emp; --查询多行数据,但是赋值给了rowtype
exception
when zero_divide then
dbm_output.put_line(‘发生了除零异常’);
when value_error then
dbm_output.put_line(‘发生了类型转换异常’);
when too_many_row then
dbm_output.put_line(‘查询多行数据,但是赋值给了rowtype’);
when no_data_found then
dbm_output.put_line(‘没有找到数据’);
when others then
dbm_output.put_line(‘发生其他异常’);
end;

猜你喜欢

转载自blog.csdn.net/artisan_young/article/details/88351671
今日推荐