Skip to content
Advertisement

Detect if value is number in 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

Advertisement

Answer

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. (trailing decimal)
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement