MySQL 表添加双值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28814425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL Table Adding Double Value
提问by berkc
I am trying to create a table on mySQL console.
我正在尝试在 mySQL 控制台上创建一个表。
CREATE TABLE TRY (Essn int(10), Pno int(2), Hours DOUBLE(40,0));
When I try to add something to table:
当我尝试向表中添加内容时:
INSERT INTO TRY ('123456789','1','32,5');
I got an error about syntax. I couldn't find the problem. Can anyone help?
我有一个关于语法的错误。我找不到问题所在。任何人都可以帮忙吗?
回答by Paul Lo
Get rid of the quote, replace 32,5with 32.5, and add VALUES
keyword should work:
去掉引号,用32.5替换32,5,然后添加VALUES
关键字应该可以工作:
INSERT INTO TRY VALUES (123456789,1,32.5);
You might also want to change your double field definition for allowing more decimal numbers in Hours
field:
您可能还想更改双字段定义以在Hours
字段中允许更多十进制数字:
CREATE TABLE TRY (Essn int(10), Pno int(2), Hours DOUBLE(40,2));
refer to MySQL's approximate valuesection for more details
有关更多详细信息,请参阅 MySQL 的近似值部分
“(M,D)” means than values can be stored with up to M digits in total, of which D digits may be after the decimal point. For example, a column defined as FLOAT(7,4) will look like -999.9999 when displayed. MySQL performs rounding when storing values, so if you insert 999.00009 into a FLOAT(7,4) column, the approximate result is 999.0001.
“(M,D)”表示最多可以存储M位的数值,其中D位可以在小数点后。例如,定义为 FLOAT(7,4) 的列在显示时看起来像 -999.9999。MySQL 在存储值时执行四舍五入,因此如果将 999.00009 插入 FLOAT(7,4) 列,则近似结果为 999.0001。
回答by ElMatze
In your creation, you defined that you do not want any digits saved after the decimal point. DOUBLE(40,0) means you have 40 digits and 0 of them after the decimal point.
在您的创建中,您定义了不希望在小数点后保存任何数字。DOUBLE(40,0) 表示您有 40 位数字,其中小数点后为 0。
Also see https://dev.mysql.com/doc/refman/5.6/en/floating-point-types.htmlfor more information.
另请参阅https://dev.mysql.com/doc/refman/5.6/en/floating-point-types.html了解更多信息。