在MySQL中将字符串(varchar)转换为double

阅读 1043 收藏 0 点赞 0 评论 0

让我们首先创建一个表:

mysql> create table DemoTable731 (Value varchar(100));

使用insert命令在表中插入一些记录-

mysql> insert into DemoTable731 values('4.50');
mysql> insert into DemoTable731 values('7.83');
mysql> insert into DemoTable731 values('8.91');
mysql> insert into DemoTable731 values('560.34');

使用select语句显示表中的所有记录-

mysql> select *from DemoTable731;

这将产生以下输出-

+--------+
| Value  |
+--------+
| 4.50   |
| 7.83   |
| 8.91   |
| 560.34 |
+--------+
4 rows in set (0.00 sec)

这是将字符串转换为double的查询-

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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号