mysql将字符串转为数字的方法:

  • 1、利用“+”运算符,语法“'字符串' + 0”;
SELECT JSON_EXTRACT(charge_sts,'$.waiter') k1,JSON_EXTRACT(charge_sts,'$.waiter')+0 k2,'0121' k3,'012'+0 k4 from test

MySQL 字符串转换成数组 mysql把字符串转化为数字_字符串

  • 2、利用cast()函数,语法“cast('字符串' as 数值类型)”;
SELECT JSON_EXTRACT(charge_sts,'$.waiter') k1,CAST(JSON_EXTRACT(charge_sts,'$.waiter') AS SIGNED) k2,'0121' k3,CAST('012' AS SIGNED) k4 from mo_loan_order_charge HAVING k2=0;

MySQL 字符串转换成数组 mysql把字符串转化为数字_字符串_02

  • 3、利用convert()函数,语法“convert('字符串', 数值类型)”。
SELECT JSON_EXTRACT(charge_sts,'$.waiter') k1,CONVERT(JSON_EXTRACT(charge_sts,'$.waiter'),SIGNED) k2,'0121' k3,CONVERT('012',SIGNED) k4 from mo_loan_order_charge HAVING k2=0;

MySQL 字符串转换成数组 mysql把字符串转化为数字_值类型_03

备注:数值类型(三种):

  • 整数: SIGNED
  • 无符号整数: UNSIGNED
  • 浮点数: DECIMAL