check if “it's a number” function in Oracle

后端 未结 16 2756
一整个雨季
一整个雨季 2020-11-28 10:31

I\'m trying to check if a value from a column in an oracle (10g) query is a number in order to compare it. Something like:

select case when ( is_number(myTab         


        
16条回答
  •  自闭症患者
    2020-11-28 11:06

    Note that regexp or function approaches are several times slower than plain sql condition.

    So some heuristic workarounds with limited applicability make sence for huge scans.

    There is a solution for cases when you know for sure that non-numeric values would contain some alphabetic letters:

    select case when upper(dummy)=lower(dummy) then '~numeric' else '~alpabetic' end from dual
    

    And if you know some letter would be always present in non-numeric cases:

    select case when instr(dummy, 'X')>0 then '~alpabetic' else '~numeric' end from dual
    

    When numeric cases would always contain zero:

    select case when instr(dummy, '0')=0 then '~alpabetic' else '~numeric' end from dual
    

提交回复
热议问题