方法一:直接 加 0
select '123' + 0
方法二:函数 convert
语法:convert (value, type);
type可以为:
decimal 浮点数 signed 整数 unsigned 无符号整数
select convert('123',signed)
方法三:函数 cast
语法:cast (value as type);
type可以为:
decimal 浮点数 signed 整数 unsigned 无符号整数
select cast('123' as signed)
补充:下面看下mysql 字符串转数字的三种方式
方式一:+0

方式二:cast('字符串' as 数值类型)
数值类型,可以分为三种:
整数 : SIGNED

无符号整数 : UNSIGNED

浮点数 : DECIMAL

方式三:convert('字符串', 数值类型)
数值类型,同样可以分为三种:
整数 : SIGNED

无符号整数 : UNSIGNED

浮点数 : DECIMAL

到此这篇关于MySQL 字符串 转换 为数字 的几种方法的文章就介绍到这了,更多相关MySQL 字符串 转换 为数字内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

 
               
               
               
               
               
 
  