加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

mysql – 使用DECIMAL的原因(31,0)

发布时间:2020-12-11 23:50:39 所属栏目:MySql教程 来源:网络整理
导读:Oracle背景中的某些人使用DECIMAL(31,0)作为整数的原因是什么.在MySQL中它效率不高.最佳答案Oracle将“INTEGER”ANSI数据类型实现为NUMBER的同义词(38) 有关详细信息,请参阅“Learn Oracle: Datatypes for SQL and PL/SQL,Numbers” 但是,下表应该用作Oracle

Oracle背景中的某些人使用DECIMAL(31,0)作为整数的原因是什么.在MySQL中它效率不高. 最佳答案 Oracle将“INTEGER”ANSI数据类型实现为NUMBER的同义词(38)

有关详细信息,请参阅“Learn Oracle: Datatypes for SQL and PL/SQL,Numbers”

但是,下表应该用作Oracle和MySQL中数据类型之间的映射:

“Oracle? Database SQL Developer Supplementary Information for MySQL Migrations”

Oracle和MySQL比较>数据类型>比较数据类型

正如here和here所解释的那样,主要区别在于Oracle NUMBER数据类型是可变长度格式,而MySQL DECIMAL(n)数据类型用于表示为每个数字或符号字符需要一个字节的字符串(在5.0.3之前)

(Oracle NUMBER Datatype) Internal Numeric Format

Oracle Database stores numeric data in
variable-length format. Each value is
stored in scientific notation,with 1
byte used to store the exponent and up
to 20 bytes to store the mantissa. The
resulting value is limited to 38
digits of precision. Oracle Database
does not store leading and trailing
zeros. For example,the number 412 is
stored in a format similar to 4.12 x
102,with 1 byte used to store the
exponent(2) and 2 bytes used to store
the three significant digits of the
mantissa(4,1,2). Negative numbers
include the sign in their length.

Taking this into account,the column
size in bytes for a particular numeric
data value NUMBER(p),where p is the
precision of a given value,can be
calculated using the following
formula:

ROUND((length(p)+s)/2))+1

where s equals zero if the number is
positive,and s equals 1 if the number
is negative.

Zero and positive and negative
infinity (only generated on import
from Oracle Database,Version 5) are
stored using unique representations.
Zero and negative infinity each
require 1 byte; positive infinity
requires 2 bytes.

(MySQL) DECIMAL Data Type Changes

The storage requirements for the
integer and fractional parts of each
value are determined separately. Each
multiple of nine digits requires four
bytes,and any remaining digits left
over require some fraction of four
bytes. […]

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 four
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 three bytes for the
remaining five digits. The six
fractional digits require three bytes.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读