在oracle中number表示数据型,p=>pricesion,s=>scale.在oracle管方网站上对number(p,s),作以下的解释:
//==============================================================================================//
The NUMBER datatype
stores zero as well as positive and negative fixed numbers with
absolute values from 1.0 x 10-130 to
(but not including) 1.0 x 10126. If you specify an
arithmetic expression whose value has an absolute value greater
than or equal to 1.0 x 10126, then Oracle returns an
error. Each NUMBER value
requires from 1 to 22 bytes.
Specify a fixed-point number using the following form:
NUMBER(p,s)
where:
-
p is
the precision, or the total number of
significant decimal digits, where the most significant digit is the
left-most nonzero digit, and the least significant digit is the
right-most known digit. Oracle guarantees the portability of
numbers with precision of up to 20 base-100 digits, which is
equivalent to 39 or 40 decimal digits depending on the position of
the decimal point.
-
s is
the scale,
or the number of digits from the decimal point to the least
significant digit. The scale can range from -84 to 127.
-
Positive scale is the number of significant digits to the right
of the decimal point to and including the least significant
digit.
-
Negative scale is the number of significant digits to the left
of the decimal point, to but not including the least significant
digit. For negative scale the least significant digit is on the
left side of the decimal point, because the actual data is rounded
to the specified number of places to the left of the decimal point.
For example, a specification of (10,-2) means to round to
hundreds.
Scale can be greater than
precision, most commonly when e notation
is used. When scale is greater than precision, the precision
specifies the maximum number of significant digits to the right of
the decimal point. For example, a column defined
as NUMBER(4,5) requires
a zero for the first digit after the decimal point and rounds all
values past the fifth digit after the decimal point.
It is
good practice to specify the scale and precision of a fixed-point
number column for extra integrity checking on input. Specifying
scale and precision does not force all values to a fixed length. If
a value exceeds the precision, then Oracle returns an error. If a
value exceeds the scale, then Oracle rounds it.
//=========================================================================//
太长了,看不是太懂.
总结一下:
1,范围:number(p,s)
a,p在1~38,s在-84~127
2,p>s时:
a,s>0时:
数据的有效数字为p个,小数部分为s个,整数部分为p-s个
如果整数大于p-s时,报错;
如果小数部分大于s,会对小数部分四舍五入,最后变成s.
b,s=0时:表示这个没有小数的数(可以理解为整形)
c,s<0时:表示这个是整形(没有小数位)
从小数点左起每|s|个位进行四舍五入,
然后整数的有效位数为p+|s|位,如果整数的数据大于p+|s|时,会报错.
3,p
a,小数起必须要存在s-p个0,如果不够,会报错;
b,小数位数大于s,会自动四舍五入;
参考一下:
http://hi.baidu.com/mars_mars/blog/item/6154198083d989d2bd3e1eae.html
http://www.cnblogs.com/hengzi/archive/2011/08/17/Oracle-10g-datatype.html