未合理使用类型 导致 ora-6502

业务反馈 之前返回结果集量小,sql执行正常,返回结果集增多后出现ora-6502, 需协助分析原因语句为,

select eis_get单位体检条件(6) from dual;

06502 官方解释如下

ORA-06502: PL/SQL: numeric or value errorstring

Cause: An arithmetic, numeric, string, conversion, or constraint error occurred. For example, this error occurs if an attempt is made to assign the value NULL to a variable declared NOT NULL, or if an attempt is made to assign an integer larger than 99 to a variable declared NUMBER(2).

Action: Change the data, how it is manipulated, or how it is declared so that values do not violate constraints.

在字段类型 使用中存在错误导致

函数如下

create or replace function eis_get单位体检条件(
                                        vi机构序号 number
                                       ) return nvarchar2 as

  Mi数量 number(4);
  Ms结果 nvarchar2(4000);
  Ms返回结果 nvarchar2(4000);
  
begin
  for r in(select 系统序号 from eis_t体检单位 where 隶属机构i=vi机构序号 and 有效状态b=1 ) loop
    Ms结果:=r.系统序号;
    select count(*) into Mi数量 from eis_t体检套餐 where 体检单位i=r.系统序号 and 有效状态B=1;
    Ms结果:=Ms结果||'|'||Mi数量;
   select count(*) into Mi数量 from eis_t体检套餐 where 体检单位i=r.系统序号 and 有效状态B=1 and 适用婚况i is null;
    Ms结果:=Ms结果||'|'||Mi数量;
    select count(*) into Mi数量 from eis_t体检套餐 where 体检单位i=r.系统序号 and 有效状态B=1 and 职业情况i is null;
    Ms结果:=Ms结果||'|'||Mi数量;
    select count(*) into Mi数量 from eis_t体检套餐 where 体检单位i=r.系统序号 and 有效状态B=1 and 职位级别i is null;
    Ms结果:=Ms结果||'|'||Mi数量;
    select count(*) into Mi数量 from eis_t体检套餐 where 体检单位i=r.系统序号 and 有效状态B=1 and 所在部门i is null;
    Ms结果:=Ms结果||'|'||Mi数量;
    Ms结果:=Ms结果||';';

    Ms返回结果:=Ms返回结果||Ms结果;
  end loop;

return Ms返回结果;

end eis_get单位体检条件;

 

随着基础业务数据是不断增加 ,Ms返回结果 拼接后会不停的增长,这里使用nvarchar会存在字节上限,会导致字节长度不足

通过排查 发现 执行到 return Ms返回结果已经开始超过nvarchar2字节上限

调整字符类型用法后问题解决

create or replace function eis_get单位体检条件(
                                        vi机构序号 number
                                       ) return 
                                        nclob 
                                        as

  Mi数量 number(18);
  Ms结果 Nclob;
  Ms返回结果 nclob;
  v_counter number:=0;

begin
  for r in(select 系统序号 from eis_t体检单位 where 隶属机构i=vi机构序号 and 有效状态b=1 ) loop
    Ms结果:=to_char(r.系统序号);
   select count(*) into Mi数量 from eis_t体检套餐 where 体检单位i=r.系统序号 and 有效状态B=1;
    Ms结果:=Ms结果||'|'||to_char(Mi数量);
   select count(*) into Mi数量 from eis_t体检套餐 where 体检单位i=r.系统序号 and 有效状态B=1 and 适用婚况i is null;
    Ms结果:=Ms结果||'|'||to_char(Mi数量);
    select count(*) into Mi数量 from eis_t体检套餐 where 体检单位i=r.系统序号 and 有效状态B=1 and 职业情况i is null;
    Ms结果:=Ms结果||'|'||to_char(Mi数量);
    select count(*) into Mi数量 from eis_t体检套餐 where 体检单位i=r.系统序号 and 有效状态B=1 and 职位级别i is null;
    Ms结果:=Ms结果||'|'||to_char(Mi数量);
   select count(*) into Mi数量 from eis_t体检套餐 where 体检单位i=r.系统序号 and 有效状态B=1 and 所在部门i is null;
    Ms结果:=Ms结果||'|'||to_char(Mi数量);
    Ms结果:=Ms结果||';';

    Ms返回结果:=Ms返回结果||Ms结果;
     v_counter:=v_counter+1;
  end loop;
  
return Ms返回结果;
end eis_get单位体检条件;

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值