Finding rows that don't contain numeric data in Oracle

前端 未结 9 580
陌清茗
陌清茗 2020-12-09 17:00

I am trying to locate some problematic records in a very large Oracle table. The column should contain all numeric data even though it is a varchar2 column. I need to find

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-09 17:23

    To get an indicator:

    DECODE( TRANSLATE(your_number,' 0123456789',' ')
    

    e.g.

    SQL> select DECODE( TRANSLATE('12345zzz_not_numberee',' 0123456789',' '), NULL, 'number','contains char')
     2 from dual
     3 /
    
    "contains char"
    

    and

    SQL> select DECODE( TRANSLATE('12345',' 0123456789',' '), NULL, 'number','contains char')
     2 from dual
     3 /
    
    "number"
    

    and

    SQL> select DECODE( TRANSLATE('123405',' 0123456789',' '), NULL, 'number','contains char')
     2 from dual
     3 /
    
    "number"
    

    Oracle 11g has regular expressions so you could use this to get the actual number:

    SQL> SELECT colA
      2  FROM t1
      3  WHERE REGEXP_LIKE(colA, '[[:digit:]]');
    
    COL1
    ----------
    47845
    48543
    12
    ...
    

    If there is a non-numeric value like '23g' it will just be ignored.

提交回复
热议问题