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

后端 未结 16 2806
一整个雨季
一整个雨季 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:05

    Saish's answer using REGEXP_LIKE is the right idea but does not support floating numbers. This one will ...

    Return values that are numeric

    SELECT  foo 
    FROM    bar
    WHERE   REGEXP_LIKE (foo,'^-?\d+(\.\d+)?$');
    

    Return values not numeric

    SELECT  foo 
    FROM    bar
    WHERE   NOT REGEXP_LIKE (foo,'^-?\d+(\.\d+)?$');
    

    You can test your regular expressions themselves till your heart is content at http://regexpal.com/ (but make sure you select the checkbox match at line breaks for this one).

提交回复
热议问题