一张合同表中的合同号字段(各种形式的数据都有,如H07HI1XG08001之类的,有的还是空值)
通过
select bb.* from 
(select t.tconcodeold,to_number(substr(t.tconcodeold,13,3)) as aa 
from pm_contract t 
where t.tconcodeold like 'HNUN(2008)网建%')bb
可以查出记录:
1 HNUN(2008)网建013号 13
2 HNUN(2008)网建014号 14
3 HNUN(2008)网建025号 25
4 HNUN(2008)网建056号 56
5 HNUN(2008)网建057号 57
6 HNUN(2008)网建058号 58
7 HNUN(2008)网建059号 59
8 HNUN(2008)网建060号 60
9 HNUN(2008)网建091号 91
10 HNUN(2008)网建092号 92
11 HNUN(2008)网建093号 93
12 HNUN(2008)网建097号 97
13 HNUN(2008)网建098号 98
14 HNUN(2008)网建099号 99但是加上where语句后,就报“无效数字”select bb.* from 
(select t.tconcodeold,to_number(substr(t.tconcodeold,13,3)) as aa 
from pm_contract t 
where t.tconcodeold like 'HNUN(2008)网建%')bb
where bb.aa = 14

解决方案 »

  1.   

    把最后的WHERE条件换成where bb.aa = '14'试试,毕竟bb.aa是字符串呀。
      

  2.   

    這個肯定是錯的啊!
    select bb.* from  
    (select t.tconcodeold,substr(t.tconcodeold,13,3) as aa  
    from pm_contract t  
    where t.tconcodeold like 'HNUN(2008)网建%')bb 
    where bb.aa like '%14%' 
    這樣應該就可以啊!
      

  3.   

    回楼上俩位,
    where bb.aa = '14' 或者 where bb.aa like '%14%' 
    我还是报错,
    我甚至连where bb.aa is not null都报“无效数字”
    主要是tconcodeold字段有很多不是这种规则的数据,

    1395 未编号
    1401 未编号
    1609 列入GG19161
    1641 列入GG19161
    1642 列入GG19161
    2370 归属于GG19162 / CUIEC-06AJN0950/0951
    1605 归属于GG19162 / CUIEC-06AJN0950/0951
    1036 工程合同(2007)号
    2058 高曼妮交来
    2057 高曼妮交来
    630 干X07-LT-21P
    260 二干四期
    67 本地网传输接入网二期线路(徐)
    1297 ?
    1298 ?
    640 T07PA1070184
    626 T07PA1070173
    等等~~~~~~~~~~~~
      

  4.   

    我在oracel數據庫中測試沒問題啊﹐
    你什么數據庫啊﹖﹖