Oracle背景中的某些人使用DECIMAL(31,0)作为整数的原因是什么.在MySQL中它效率不高.
有关详细信息,请参阅“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.