How to only select numeric data from mysql?

后端 未结 6 1114
一个人的身影
一个人的身影 2020-11-30 12:09

Does mysql have a function like is_num() which can allow me determine the data is numeric or not?

6条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 12:37

    In my case I just needed to check if data was >= 0 and not char, perhaps this is useful for you also:

    mysql> select '1'  REGEXP '^[0-9]+$' as result;
    +--------+
    | result |
    +--------+
    |      1 | 
    +--------+
    1 row in set (0.16 sec)
    
    mysql> select '1a'  REGEXP '^[0-9]+$' as result;
    +--------+
    | result |
    +--------+
    |      0 | 
    +--------+
    

提交回复
热议问题