我想查找列值以数字开头的所有行。
它适用于此请求:
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')
但它太长了。
感谢您的帮助。
答案 0 :(得分:19)
Regexp_like会派上用场,而且会更短
where regexp_like(trim(col_name), '^[0-9]')
或使用字符类
where regexp_like(trim(col_name), '^[[:digit:]]')
答案 1 :(得分: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')
答案 2 :(得分: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。