关于系统例外和自定义例外

“`
**–系统例外: no_data_found,to_many_rows,Zero_Divide(被零除),Value_error(算术或转换错误),Timeout_on_resource (在等待资源时发生超时)
–自定义例外 : 查询 不存在的记录**
set serveroutput on

declare
–定义光标(此查询没有数据)
cursor tano is select t.tano from cfg_fund t where t.fundcode = ‘1q’;
no_tano_found exception;
ptano cfg_fund.tano%type;
pnum number;
begin
open tano;
select t.tano into ptano from cfg_fund t ;
ptano := 1/0;
pnum := ‘abc’;

fetch tano into ptano;

if tano%notfound then 
  --抛出自定义例外
 raise no_tano_found;
end if;

–关闭光标
–如果上面的语句出现例外的话,按照代码执行顺序是不会关闭光标的,此时oracle 自动启动 pmon(process monitor),自动释放历史遗留垃圾和资源(在此例中就是关闭光标了)
close tano;
exception
–上面2条语句,如果上面一句出现例外,则终止程序了(相当于后面的赋值语句被短路了).
when no_data_found then dbms_output.put_line(‘没有找到数据哦’);
when too_many_rows then dbms_output.put_line(‘select into 语句匹配到多个行’);
when Zero_Divide then dbms_output.put_line(‘0不能做除数’);
when Value_error then dbms_output.put_line(‘算术或者转换错误’);
–捕获自定义例外
when no_tano_found then dbms_output.put_line(‘没有找到tano’);
when others then dbms_output.put_line(‘其他例外’);
end;
/“`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值