I was trying to write a MySQL stored procedure today that was crying out for the is_numeric function – the one that doesn’t exist. I wanted to select two different things depending on whether the value in a field was numeric or not.

Luckily trying to convert a non integer into an integer returns a 0 (at least in the version I am running it does). Hence testing for CONVERT(field_value,SIGNED INTEGER)>0 is pretty close to what I’d expect from the missing is_numeric(field_value). In my case it is good enough as I know that I am dealing with integers not decimals, and none of them are 0!

Job done!

NB: MySQL version 5.0.22.

Advertisements