Numeric Types
835
Type
Storage
Minimum Value
Maximum Value
(Bytes)
(Signed/Unsigned)
Signed/Unsigned)
0
65535
MEDIUMINT
3
-8388608
8388607
0
16777215
INT
4
-2147483648
2147483647
0
4294967295
BIGINT
8
-9223372036854775808
9223372036854775807
0
18446744073709551615
11.1.4.2. Fixed-Point Types (Exact Value) -
DECIMAL
,
NUMERIC
The
DECIMAL
and
NUMERIC
types store exact numeric data values. These types are used when it
is important to preserve exact precision, for example with monetary data. In MySQL,
NUMERIC
is
implemented as
DECIMAL
, so the following remarks about
DECIMAL
apply equally to
NUMERIC
.
As of MySQL 5.0.3,
DECIMAL
values are stored in binary format. Previously, they were stored as
strings, with one character used for each digit of the value, the decimal point (if the scale is greater
than 0), and the “
-
” sign (for negative numbers). See
Section 12.17, “Precision Math”
.
In a
DECIMAL
column declaration, the precision and scale can be (and usually is) specified; for
example:
salary DECIMAL(5,2)
In this example,
5
is the precision and
2
is the scale. The precision represents the number of significant
digits that are stored for values, and the scale represents the number of digits that can be stored
following the decimal point.
Standard SQL requires that
DECIMAL(5,2)
be able to store any value with five digits and two
decimals, so values that can be stored in the
salary
column range from
-999.99
to
999.99
. MySQL
enforces this limit as of MySQL 5.0.3. Before 5.0.3, on the positive end of the range, the column could
actually store numbers up to
9999.99
. (For positive numbers, MySQL 5.0.2 and earlier used the byte
reserved for the sign to extend the upper end of the range.)
In standard SQL, the syntax
DECIMAL(M)
is equivalent to
DECIMAL(M,0)
. Similarly, the syntax
DECIMAL
is equivalent to
DECIMAL(M,0)
, where the implementation is permitted to decide the value
of
M
. MySQL supports both of these variant forms of
DECIMAL
syntax. The default value of
M
is 10.
If the scale is 0,
DECIMAL
values contain no decimal point or fractional part.
The maximum number of digits for
DECIMAL
is 65 (64 from MySQL 5.0.3 to 5.0.5). Before MySQL
5.0.3, the maximum range of
DECIMAL
values is the same as for
DOUBLE
, but the actual range for a
given
DECIMAL
column can be constrained by the precision or scale for a given column. When such
a column is assigned a value with more digits following the decimal point than are permitted by the
specified scale, the value is converted to that scale. (The precise behavior is operating system-specific,
but generally the effect is truncation to the permissible number of digits.)
11.1.4.3. Floating-Point Types (Approximate Value) -
FLOAT
,
DOUBLE
The
FLOAT
and
DOUBLE
types represent approximate numeric data values. MySQL uses four bytes for
single-precision values and eight bytes for double-precision values.
For
FLOAT
, the SQL standard permits an optional specification of the precision (but not the range of
the exponent) in bits following the keyword
FLOAT
in parentheses. MySQL also supports this optional
precision specification, but the precision value is used only to determine storage size. A precision from
Содержание 5.0
Страница 1: ...MySQL 5 0 Reference Manual ...
Страница 18: ...xviii ...
Страница 60: ...40 ...
Страница 396: ...376 ...
Страница 578: ...558 ...
Страница 636: ...616 ...
Страница 844: ...824 ...
Страница 1234: ...1214 ...
Страница 1426: ...MySQL Proxy Scripting 1406 The following diagram shows an overview of the classes exposed by MySQL Proxy ...
Страница 1427: ...MySQL Proxy Scripting 1407 ...
Страница 1734: ...1714 ...
Страница 1752: ...1732 ...
Страница 1783: ...Configuring Connector ODBC 1763 ...
Страница 1793: ...Connector ODBC Examples 1773 ...
Страница 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Страница 1842: ...Connector Net Installation 1822 5 Once the installation has been completed click Finish to exit the installer ...
Страница 1864: ...Connector Net Visual Studio Integration 1844 Figure 20 24 Debug Stepping Figure 20 25 Function Stepping 1 of 2 ...
Страница 2850: ...2830 ...
Страница 2854: ...2834 ...
Страница 2928: ...2908 ...
Страница 3000: ...2980 ...
Страница 3122: ...3102 ...
Страница 3126: ...3106 ...
Страница 3174: ...3154 ...
Страница 3232: ...3212 ...