https://dev.mysql.com/doc/refman/8.0/en/fixed-point-types.html

This section discusses the characteristics of the DECIMAL data type (and its synonyms), with particular regard to the following topics:

  • Maximum number of digits

  • Storage format

  • Storage requirements

  • The nonstandard MySQL extension to the upper range of DECIMAL columns

The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the arguments are as follows:

  • M is the maximum number of digits (the precision). It has a range of 1 to 65.

  • D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.

If D is omitted, the default is 0. If M is omitted, the default is 10.

The maximum value of 65 for M means that calculations on DECIMAL values are accurate up to 65 digits. This limit of 65 digits of precision also applies to exact-value numeric literals, so the maximum range of such literals differs from before. (There is also a limit on how long the text of DECIMAL literals can be; see Section 12.24.3, “Expression Handling”.)

Values for DECIMAL columns are stored using a binary format that packs nine decimal digits into 4 bytes. The storage requirements for the integer and fractional parts of each value are determined separately. Each multiple of nine digits requires 4 bytes, and any remaining digits left over require some fraction of 4 bytes. The storage required for remaining digits is given by the following table.

Leftover Digits Number of Bytes
0 0
1–2 1
3–4 2
5–6 3
7–9 4

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.

DECIMAL columns do not store a leading + character or - character or leading 0 digits. If you insert +0003.1 into a DECIMAL(5,1) column, it is stored as 3.1. For negative numbers, a literal - character is not stored.

DECIMAL columns do not permit values larger than the range implied by the column definition. For example, a DECIMAL(3,0) column supports a range of -999 to 999. A DECIMAL(M,D) column permits up to M - D digits to the left of the decimal point.

The SQL standard requires that the precision of NUMERIC(M,D) be exactly M digits. For DECIMAL(M,D), the standard requires a precision of at least M digits but permits more. In MySQL, DECIMAL(M,D) and NUMERIC(M,D) are the same, and both have a precision of exactly M digits.

For a full explanation of the internal format of DECIMAL values, see the file strings/decimal.c in a MySQL source distribution. The format is explained (with an example) in the decimal2bin() function.

[转帖]12.24.2 DECIMAL Data Type Characteristics的更多相关文章

  1. DECIMAL Data Type

    In MySQL, DECIMAL(M,D) and NUMERIC(M,D) are the same, and both have a precision of exactly M digits. ...

  2. mysql data type <----> java data type (数值)

    https://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html +----------------------------+---- ...

  3. MySql and Oracle Data Type Mappings

    the default settings used by SQL Developer to convert data types from MySQL to Oracle. SQL Developer ...

  4. 【转载】salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解

    salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解   建立好的数据表在数据库中查看有很多方式,本人目前采用以下两种方式查看数据表. 1.采用schem ...

  5. salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解

    建立好的数据表在数据库中查看有很多方式,本人目前采用以下两种方式查看数据表. 1.采用schema Builder查看表结构以及多表之间的关联关系,可以登录后点击setup在左侧搜索框输入schema ...

  6. The conversion of a varchar data type to a datetime data type resulted in an out-of-range value

    刚刚有在程序中,传递一个空值至MS SQL Server数据库,这个值的数据类型为DATETIME执行时,它却发生了如标题提示的异常:The conversion of a varchar data ...

  7. Extended Data Type Properties [AX 2012]

    Extended Data Type Properties [AX 2012] This topic has not yet been rated - Rate this topic Updated: ...

  8. 1月21日 Reference Data Type 数据类型,算法基础说明,二分搜索算法。(课程内容)

    Reference Datat Types 引用参考数据类型 -> 组合数据类型 Array, Hash和程序员自定义的复合资料类型 组合数据的修改: 组合数据类型的变量,不是直接存值,而是存一 ...

  9. C++数据类型(data type)介绍

    在编写程序时,数据类型(data type)定义了使用存储空间的(内存)的方式. 程序员通过定义数据类型(data type),告诉特定存储空间这里要存储的数据类型是什么,以及你即将操作他的方式.(注 ...

  10. How to check sqlsever table data type identity status ?

    Unlike in Oracle, sqlserver has an special data type in order by make identity growth. But what abou ...

随机推荐

  1. zabbix 利用脚本发邮件(mail)

    # 源码安装mailx tar jxvf mailx-12.3.tar.bz2 make && make install UCBINSTALL=/usr/bin/install #yu ...

  2. Sermant重磅更新,1.3.0 release版本发布

    本文分享自华为云社区<新特性速览!Sermant重磅更新,1.3.0 release版本发布>,作者:华为云开源. Sermant社区在12月份正式发布了1.3.0 release版本,这 ...

  3. MyBatis中SQL语句优化小结

    摘要:MyBatis 作为一款优秀的持久层框架,它支持自定义SQL.存储过程以及高级映射. MyBatis 作为一款优秀的持久层框架,它支持自定义SQL.存储过程以及高级映射.它免除了几乎所有的 JD ...

  4. 云图说丨初识云应用引擎CAE

    摘要:开发运营一个应用软件,面临种种挑战:软件栈厚重.开发上线慢.资源易浪费.运维投入高.突发流量应对困难. 华为云应用引擎CAE面对挑战,一扫而光!! 本文分享自华为云社区<[云图说] | 第 ...

  5. 后CNN探索,如何用RNN进行图像分类

    摘要:RNN可以用于描述时间上连续状态的输出,有记忆功能,能处理时间序列的能力,让我惊叹. 本文分享自华为云社区<用RNN进行图像分类--CNN之后的探索>,作者: Yin-Manny. ...

  6. 论文解读丨LayoutLM: 面向文档理解的文本与版面预训练

    摘要:LayoutLM模型利用大规模无标注文档数据集进行文本与版面的联合预训练,在多个下游的文档理解任务上取得了领先的结果. 本文分享自华为云社区<论文解读系列二十五:LayoutLM: 面向文 ...

  7. 万字保姆级长文——Linkedin元数据管理平台Datahub离线安装指南

    ​ 元数据管理平台Datahub最近的热度越来越高.已经更新到了0.8.40的版本,来咨询我的小伙伴也越来越多,特别是安装过程有很多问题. ​ 考虑到有些企业部分数据服务是部署在内网的,那么离线安装D ...

  8. [ERROR] Error executing Maven. [ERROR] 1 problem was encountered while building the effective settings

    原因: maven 的配置文件 setting.xml 有错. 比如在配置文件中多了一行: 导致配置文件的格式不正确.

  9. 如何在Windows上将iOS应用上传到App Store

      Application Uploader iOS App上架工具是一款非常好用的针对iOS苹果应用程序软件开发的实用编程工具,它的主要作用是帮助用户进行快速的程序应用设计和程序应用调试,节省用户进 ...

  10. LAS Spark+云原生:数据分析全新解决方案

    更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 随着数据规模的迅速增长和数据处理需求的不断演进,云原生架构和湖仓分析成为了现代数据处理的重要趋势.在这个数字化时代 ...