8

我想找到列值以数字开头的所有行。

它适用于这个请求:

    WHERE trim(u_ods_val3.ods_itn_PHRSBMO.NO_ART_TECH_OI)    IS NOT NULL
  AND (SUBSTR(u_ods_val3.ODS_ITN_PHRSBMO.NO_ART_TECH_OI,0,1)='0'
  OR SUBSTR(u_ods_val3.ODS_ITN_PHRSBMO.NO_ART_TECH_OI,0,1)  ='1'
  OR SUBSTR(u_ods_val3.ODS_ITN_PHRSBMO.NO_ART_TECH_OI,0,1)  ='2 '
  OR SUBSTR(u_ods_val3.ODS_ITN_PHRSBMO.NO_ART_TECH_OI,0,1)  ='3'
  OR SUBSTR(u_ods_val3.ODS_ITN_PHRSBMO.NO_ART_TECH_OI,0,1)  ='4'
  OR SUBSTR(u_ods_val3.ODS_ITN_PHRSBMO.NO_ART_TECH_OI,0,1)  ='5'
  OR SUBSTR(u_ods_val3.ODS_ITN_PHRSBMO.NO_ART_TECH_OI,0,1)  ='6'
  OR SUBSTR(u_ods_val3.ODS_ITN_PHRSBMO.NO_ART_TECH_OI,0,1)  ='7'
  OR SUBSTR(u_ods_val3.ODS_ITN_PHRSBMO.NO_ART_TECH_OI,0,1)  ='8'
  OR SUBSTR(u_ods_val3.ODS_ITN_PHRSBMO.NO_ART_TECH_OI,0,1)  ='9')

但它太长了。

谢谢您的帮助。

4

3 回答 3

20

Regexp_like会派上用场而且更短

where regexp_like(trim(col_name), '^[0-9]')

或使用字符类

where regexp_like(trim(col_name), '^[[:digit:]]')
于 2012-10-01T09:21:26.917 回答
2

尝试使用in

WHERE trim(u_ods_val3.ods_itn_PHRSBMO.NO_ART_TECH_OI)    IS NOT NULL
  AND SUBSTR(u_ods_val3.ODS_ITN_PHRSBMO.NO_ART_TECH_OI,0,1) in ('0','1','2','3','4','5','6','7','8','9')
于 2012-10-01T09:20:37.947 回答
1

BETWEEN是你所需要的全部!(NOT NULL在这种情况下是隐含的!)

WHERE SUBSTR(u_ods_val3.ODS_ITN_PHRSBMO.NO_ART_TECH_OI,0,1) between '0' and '9'

如果您在该列上有索引,并且不介意此解决方案的小脏,您甚至可以加快速度:

WHERE u_ods_val3.ODS_ITN_PHRSBMO.NO_ART_TECH_OI between '0' and '9~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'

这假设 NO_ART_TECH_OI 不包含 ascii 代码 > 126 的字符。

于 2012-10-01T09:28:29.203 回答