您的位置:首页 > 数据库 > Oracle

oracle to_namber之后报ora-01722:无效数字

2017-03-02 00:15 567 查看
写的sql:

select
to_number(substr(B.年龄, 1, instr(B.年龄, '天') - 1)) as 年龄, A.病人id, A.主页id
from 病案主页 A, 病人信息 B
where A.病人ID = B.病人ID
and A.主页ID = B.主页ID
and to_number(substr(B.年龄, 1, instr(B.年龄, '天') - 1)) < 29
and B.年龄 not like '%岁%'
and B.年龄 not like '%月%'
报错:



加上强制规则,运行通过:
select /*+rule*/ to_number(substr(B.年龄, 1, instr(B.年龄, '天') - 1)) as 年龄, A.病人id, A.主页id from 病案主页 A, 病人信息 B where A.病人ID = B.病人ID and A.主页ID = B.主页ID and to_number(substr(B.年龄, 1, instr(B.年龄, '天') - 1)) < 29 and B.年龄 not like '%岁%' and B.年龄 not like '%月%'
注意:and to_number(substr(B.年龄, 1, instr(B.年龄, '天') - 1)) < 29
不能放在最后一个条件,否则也会报错!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oracle ora-01722 namber