检测MySQL中的值是否为数字
有没有办法检测一个值是否是 MySQL 查询中的数字?比如
Is there a way to detect if a value is a number in a MySQL query? Such as
SELECT *
FROM myTable
WHERE isANumber(col1) = true
推荐答案
这应该适用于大多数情况.
This should work in most cases.
SELECT * FROM myTable WHERE concat('',col1 * 1) = col1
它不适用于非标准数字,例如
It doesn't work for non-standard numbers like
1e4
1.2e5
123.
(尾随十进制)
1e4
1.2e5
123.
(trailing decimal)
相关文章