在MySql中将VARCHAR转换为DECIMAL值 [英] Converting VARCHAR to DECIMAL values in MySql

查看:1617
本文介绍了在MySql中将VARCHAR转换为DECIMAL值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将包含字符串值(例如吃)和浮动值(例如0.87)的CSV文件导入到phpMyAdmin数据库中的表中.掌握所有字符串值并仅保留具有十进制值的行后,需要将此类值从VARCHAR转换为DECIMAL/FLOAT,以便可以对该属性执行MAX().

I have imported a CSV file that contains string values (eg.eating) and floating values (eg. 0.87) into a table in my phpMyAdmin database. After I get ride of all the string values and retain only the rows that have the decimal values, I need to convert such values from VARCHAR to DECIMAL/FLOAT so that I can perform a MAX() on this attribute.

我该怎么做?每次我尝试通过phpMyAdmin中的GUI进行此操作时,我所有的值都会自动四舍五入为0和1s.

How do I do this? Each time I try doing this through the GUI in phpMyAdmin, all my values are automatically rounded off to 0 and 1s.

请帮助我!

推荐答案

我认为,如果您对MySQL具有管理员权限,则需要尝试在MySQL上执行类似的操作.

I think you need to try doing something like this on your MySQL if you have admin privilege on your MySQL.

ALTER TABLE表名修改列名DECIMAL(M,D)

ALTER TABLE tablename MODIFY columnname DECIMAL(M,D)

有关M,D变量,请阅读此内容- http://dev.mysql.com/doc/refman/5.0/zh-CN/fixed-point-types.html

for the M,D variables, read this - http://dev.mysql.com/doc/refman/5.0/en/fixed-point-types.html

MySQL应该能够自动将文本转换为数字.只是MySQL中的数据类型可能不是十进制,这就是为什么不能存储任何十进制的原因.

And MySQL should be able to automatically converting a text to a numeric. Just that the data type in MySQL might not be a decimal yet that's why you can't store any decimal.

这篇关于在MySql中将VARCHAR转换为DECIMAL值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆