ORA-01722错误

今天遇到个很头疼的sql问题。。ORA-01722错误

数据库中有个字段QZFW起止范围是varchar类型,存放的数据格式是"数字编号"-"数字编号" 如:0012-1345 现在我想输入个条件a,使字段满足 QZFW中'-'前面的数字<= a <= QZFW中‘-’后面的数字。。


我写的sql如下:55000是条件a,,,

select * from (select to_number(substr(QZFW,0,instr(QZFW,'-')-1)) nbefore,
to_number(substr(QZFW,instr(QZFW,'-')+1,length(QZFW))) nafter,
QZFW as qzfw_C from TBL_01 Where translate(QZFW,'\1234567890-','\') is null and (length(QZFW) - length(replace(QZFW,'-')))/length('-')=1) t
where t.nbefore<=55000 and t.nafter >=55000


但是如果输入条件太大如:304000582 就会报“ORA-01722: 无效数字”错误。。。

把同样的数据导入到一个新建的表中。用同样的条件查询就没有问题,无语了。
insert into tt(id) select qzfw_c from (select to_number(substr(QZFW,0,instr(QZFW,'-')-1)) nbefore,
to_number(substr(QZFW,instr(QZFW,'-')+1)) nafter,
QZFW as qzfw_C from T_C602BC0C604B4 Where instr(QZFW,'-') > 1
and instr(QZFW,'-') < length(QZFW)and translate(QZFW,'\1234567890-','\') is null and (length(QZFW) - length(replace(QZFW,'-')))/length('-')=1) t


select * from (select to_number(substr(id,0,instr(id,'-')-1)) nbefore,
to_number(substr(id,instr(id,'-')+1)) nafter,
id as qzfw_C from tt Where instr(id,'-') > 1
and instr(id,'-') < length(id) and translate(id,'\1234567890-','\') is null and (length(id) - length(replace(id,'-')))/length('-')=1) t
where t.nbefore<=5501098080 and t.nafter>=5501098080


translate(id,'\1234567890-','\') is null 是确保id是中除了'-'就是数字。
(length(id) - length(replace(id,'-')))/length('-')=1 是确保id中有一个'-'字符。


最后没有使用数字比较,都转换为同长度的字符串,然后比较。。


select * from
(select QZFW as qzfw_C,
lpad((substr(QZFW, 0, instr(QZFW, '-') - 1)),13,'0') as nbefore,
lpad((substr(QZFW, instr(QZFW, '-') + 1)),13,'0') as nafter
from T_C602BC0C604B4
Where translate(QZFW, '\1234567890-', '\') is null
and (length(QZFW) - length(replace(QZFW, '-'))) / 1 = 1
) where nbefore<=lpad(550109808022,13,'0') and nafter>=lpad(550109808022,13,'0')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值