在 MySQL 中将字符串 (varchar) 转换为双精度型
mysqlmysqli database更新于 2025/10/4 12:28:17
首先我们创建一个表:
mysql> create table DemoTable731 (Value varchar(100)); Query OK, 0 rows affected (0.50 sec)
使用 insert 在表中插入一些记录 command -
mysql> insert into DemoTable731 values('4.50');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable731 values('7.83');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable731 values('8.91');
Query OK, 1 row affected (0.25 sec)
mysql> insert into DemoTable731 values('560.34');
Query OK, 1 row affected (0.21 sec)
使用 select 语句显示表中的所有记录 -
mysql> select *from DemoTable731;
这将产生以下输出 -
+--------+ | Value | +--------+ | 4.50 | | 7.83 | | 8.91 | | 560.34 | +--------+ 4 rows in set (0.00 sec)
这是将字符串转换为双精度的查询 -
mysql> select Value+0.0 AS demo from DemoTable731;
这将产生以下输出 -
+-----------+ | demo | +-----------+ | 4.5 | | 7.83 | | 8.91 | | 560.34 | +-----------+ 4 rows in set (0.28 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

