Oracle SQL : search column that starts with digits

astrotouf picture astrotouf · Oct 1, 2012 · Viewed 23.3k times · Source

I'd like to find all the rows which column value begins with a digit.

Its works well with this request :

    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')

But it is too long.

Thank you for your help.

Answer

Nick Krasnov picture Nick Krasnov · Oct 1, 2012

Regexp_like would be in handy and much shorter

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

or using character class

where regexp_like(trim(col_name), '^[[:digit:]]')