在MySQL中将字符串(varchar)转换为double
让我们首先创建一个表:
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)