gpt4 book ai didi

MySQL 小数类型超出范围错误

转载 作者:行者123 更新时间:2023-12-02 11:13:36 25 4
gpt4 key购买 nike

这段代码:

DROP DATABASE IF EXISTS `my_db`;
CREATE DATABASE `my_db`;
CREATE TABLE `my_db`.`my_table` (
`id` integer NOT NULL AUTO_INCREMENT,
`multiplier` decimal(18, 10) NOT NULL,
PRIMARY KEY (`id`)
) Engine=InnoDB;

INSERT INTO `my_db`.`my_table` (`multiplier`) VALUES (100000000.0);

返回错误:

Error Code: 1264. Out of range value for column 'multiplier' at row 1
为什么?逗号之前只有 9 位数字,而该列应该工作到 18 位数字 - 或者我在这里遗漏了一些东西?谢谢。

最佳答案

decimal(18, 10) 表示小数点后 10 位、小数点前 8 位,直到 18 位

https://dev.mysql.com/doc/refman/5.1/en/precision-math-decimal-characteristics.html

For example, a DECIMAL(18,9) column has nine digits on either side of the decimal point, so the integer part and the fractional part each require 4 bytes. A DECIMAL(20,6) column has fourteen integer digits and six fractional digits. The integer digits require four bytes for nine of the digits and 3 bytes for the remaining five digits. The six fractional digits require 3 bytes.

关于MySQL 小数类型超出范围错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33348508/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com