ORACLE 跳出循环

问题:

RA-06502: PL/SQL: 数字或值错误 : 字符串缓存区太小 
ora-06512:在"xx.xxxxxxxx",line 316 
ora-1403 :no data found 
ora-06512:at line 1

原因分析:
根据RA-06502,判断定义的变量空间太小,结合ora-1403 :no data found,判断是因为变量赋值为空的时候产生的报错。

找到错误位置:

if count > 0 then
  for cc in (select pk_id from ss.tb_sss)
    loop
        select pro_id 
          into v_pro_id 
         from ss.tb_ee t
         where t.pk_id = cc.pk_id 
         
      begin 
        ss.pro_test_tmp(v_pro_id );
      end;
    end loop;
  end if;

查出 :
select pk_id from ss.tb_sss 为210行数据
select pro_id
from ss.tb_ee t
where t.pk_id in (select pk_id from ss.tb_sss)
为200 行数据;

所以当用 条件 where t.pk_id = cc.pk_id 进行匹配时 必定有为空现象出现

select ... into... from ... 会报错。

这需要进行报错处理,同时为空时,需要跳出本次循环,不执行循环中的存储过程。

重点:
跳出本次循环: continue;
跳出循环: exit;

更正代码:

if count > 0 then
  for cc in (select pk_id from ss.tb_sss)
    loop
      begin 
        select pro_id 
          into v_pro_id 
         from ss.tb_ee t
         where t.pk_id = cc.pk_id 
        exception
          when others then
            continue;
         
        ss.pro_test_tmp(v_pro_id );
      end;
    end loop;
  end if;
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值