[转帖]12.24.2 DECIMAL Data Type Characteristics
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
DECIMALcolumns
The declaration syntax for a DECIMAL column is DECIMAL(. The ranges of values for the arguments are as follows:M,D)
Mis the maximum number of digits (the precision). It has a range of 1 to 65.Dis 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 thanM.
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( column permits up to M,D)M - D digits to the left of the decimal point.
The SQL standard requires that the precision of NUMERIC( be exactly M,D)M digits. For DECIMAL(, the standard requires a precision of at least M,D)M digits but permits more. In MySQL, DECIMAL( and M,D)NUMERIC( are the same, and both have a precision of exactly M,D)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的更多相关文章
- DECIMAL Data Type
In MySQL, DECIMAL(M,D) and NUMERIC(M,D) are the same, and both have a precision of exactly M digits. ...
- mysql data type <----> java data type (数值)
https://dev.mysql.com/doc/refman/5.7/en/storage-requirements.html +----------------------------+---- ...
- MySql and Oracle Data Type Mappings
the default settings used by SQL Developer to convert data types from MySQL to Oracle. SQL Developer ...
- 【转载】salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解
salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解 建立好的数据表在数据库中查看有很多方式,本人目前采用以下两种方式查看数据表. 1.采用schem ...
- salesforce 零基础开发入门学习(四)多表关联下的SOQL以及表字段Data type详解
建立好的数据表在数据库中查看有很多方式,本人目前采用以下两种方式查看数据表. 1.采用schema Builder查看表结构以及多表之间的关联关系,可以登录后点击setup在左侧搜索框输入schema ...
- 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 ...
- Extended Data Type Properties [AX 2012]
Extended Data Type Properties [AX 2012] This topic has not yet been rated - Rate this topic Updated: ...
- 1月21日 Reference Data Type 数据类型,算法基础说明,二分搜索算法。(课程内容)
Reference Datat Types 引用参考数据类型 -> 组合数据类型 Array, Hash和程序员自定义的复合资料类型 组合数据的修改: 组合数据类型的变量,不是直接存值,而是存一 ...
- C++数据类型(data type)介绍
在编写程序时,数据类型(data type)定义了使用存储空间的(内存)的方式. 程序员通过定义数据类型(data type),告诉特定存储空间这里要存储的数据类型是什么,以及你即将操作他的方式.(注 ...
- 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 ...
随机推荐
- 实现两个 JSON 对象的对比
问题描述 在 Java 中,对于两个对象的对比,如果没有重写 equals 方法,那么将会默认使用 Object 默认的 equals 方法来比较两个对象.这种比较方式是通过比较两个对象的内存地址是否 ...
- 【manim动画教程】--目录(完结)
manim是一个生成数学教学视频的动画引擎. 它用编程的方式创建精美的数学动画,让数学更加易懂. 本教程简单介绍了 manim 的基本使用方式,基于 v0.17.2 版本 manim 安装 manim ...
- HDU 4893 线段树延迟标记
原题链接 题意 初始有一长度为n,全为0的序列 每次我们可以对这个序列进行三种操作: 1.将某个位置的数加上d 2.输出某个区间的和 3.将某个区间内每个数字变为与其最接近的斐波那契数,如果有两个最相 ...
- 神经网络基础篇:详解导数(Derivatives)
导数 一个函数\(f(a)=3a\),它是一条直线.下面来简单理解下导数.让 看看函数中几个点,假定\(a=2\),那么\(f(a)\)是\(a\)的3倍等于6,也就是说如果\(a=2\),那么函数\ ...
- GaussDB技术解读系列:高级压缩之OLTP表压缩
本文分享自华为云社区<DTCC 2023专家解读 | GaussDB技术解读系列:高级压缩之OLTP表压缩>,作者:GaussDB 数据库 . 8月16日,第14届中国数据库技术大会(DT ...
- 业务并发度不够,数仓的CN可以来帮忙
摘要: CN全称协调节点(Coordinator Node),是和用户关系最密切也是DWS内部非常重要的一个组件,它负责提供外部应用接口.优化全局执行计划.向Datanode分发执行计划,以及汇总.处 ...
- WebKit三件套(3):WebKit之Port篇
了解其有关Port方面的设计,从而了解究竟如何能移植WebKit到自己的应用中. WebKitPort方面的内容是可以很广的,例如可将不同的图形库.网络库与WebCore集成,提供不同的Port接口供 ...
- vue2升级vue3: TSX Vue 3 Composition API Refs
在vue2时代,$refs 直接操作子组件 this.$refs.gridlayout.$children[index]; 虽然不推荐这么做,但是确实非常好用.但是vue2快速迁移到vue3,之前的这 ...
- 从银行数字化转型来聊一聊,火山引擎 VeDI 旗下 ByteHouse 的应用场景
更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 近日,火山引擎凭借云原生数据分析平台 ByteHouse,成功入围行业媒体 Internet Deep(互联网周刊 ...
- ByteHouse技术白皮书正式发布,云数仓核心技术能力首次全面解读(内附下载链接)
更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 近日,<火山引擎云原生数据仓库 ByteHouse 技术白皮书>正式发布. 在数字化浪潮下,伴随着公有 ...