欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

MySQL判断字符串是否是数字

程序员文章站 2022-04-20 16:23:24
...

查询表table_name中col_name(字符串类型)的值是数字的记录 SELECT col_name,CAST(col_name AS UNSIGNED INTEGER) AS val FROM table_name WHERE col_name=0 OR col_name0 HAVING CHAR_LENGTH(col_name)=CHAR_LENGTH(val);

查询表table_name中col_name(字符串类型)的值是数字的记录

SELECT col_name,CAST(col_name AS UNSIGNED INTEGER) AS val
FROM table_name
WHERE col_name="0" OR col_name>0
HAVING CHAR_LENGTH(col_name)=CHAR_LENGTH(val);