MySQL数据类型从varchar转换为float [英] MySQL datatype conversion from varchar to float
本文介绍了MySQL数据类型从varchar转换为float的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在执行查询时如何在MySQL中将varchar
转换为float
?
How might I convert a varchar
into a float
in MySQL while executing a query?
推荐答案
您不能使用浮点类型在mysql中强制转换该值.
You cannot cast the value in mysql using float type.
该类型可以使用以下值:
The type can use following values:
- BINARY [(N)]
- CHAR [(N)]
- 日期
- DATETIME
- DECIMAL [(M [,D])]
- 签名[整数]
- 时间
- 未签名的[INTEGER]
因此,在您的情况下,您必须使用小数,例如:
So in your case you have to use decimal, e.g:
select cast(amount AS DECIMAL(10,2)) as 'float-value' from amounts
这篇关于MySQL数据类型从varchar转换为float的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文