【问题标题】:MySQL Workbench out of range value for decimal numberMySQL Workbench 十进制数的值超出范围
【发布时间】:2017-12-09 12:23:24
【问题描述】:

我想创建一个表

create table Oceny_projekty
(
   OProj_Id             int not null  comment '',
   ID_Projektu          int  comment '',
   ID_Studenta          int  comment '',
   OProj_Ocena          decimal(1,1)  comment '',
   OProj_Data           date  comment '',
   primary key (OProj_Id)
);

并用 PowerDesigner 生成的示例数据填充它

insert into Oceny_projekty (OProj_Id, ID_Projektu, ID_Studenta, OProj_Ocena, OProj_Data)
    values (2, 18, 10, '2.5', '1857-12-25');

我有这个:

插入 Oceny_projekty(OProj_Id、ID_Projektu、ID_Studenta、 OProj_Ocena, OProj_Data) 值 (2, 18, 10, '2.5', '1857-12-25') 错误 代码:1264。第 1 行“OProj_Ocena”列的值超出范围

如何修改可以接受十进制数字的命令? (整数没有问题) 使用 MySQL Workbench 6.3、PowerDesigner 16.6

提前致谢!

【问题讨论】:

标签: mysql sql entity workbench powerdesigner


【解决方案1】:

OProj_Ocena 声明为decimal(1,1) 意味着它有0 个整数位(precision - scale = 1 - 1 = 0)和1 个小数位。它只能存储值0, 0.1, 0.2 ... 0.9

你需要的数据类型大概是decimal(2,1)

【讨论】:

    【解决方案2】:

    用另一种方式表示 Marek Grzenkowicz 的答案,DECIMAL(M, D):

    M = D +(整数位数)。 See 12.25.2 DECIMAL Data Type Characteristics

    因此,确定您想要的整数位数、小数点左侧的位数以及您需要的小数位数 (D) 并将它们相加得到 M。IMO,他们应该使用短语“整数位”或“整数位”以使这一点更加明显,即使他们所说的意味着 M 代表所有数字。起初我误解了这一点,直到我重读了几次他们的描述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-06
      • 1970-01-01
      • 2014-04-26
      • 1970-01-01
      • 2022-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多