NUMBER数据类型的定义格式是:NUMBER(p,s)。本文对定义中的p(precision)和s(scale)做一个解释和总结。1.官方文档中有关NUMBER数据类型的描述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.
2.关于NUMBER数据类型的测试
create table test ( a number(1,3));
insert into test values(0.12);
*
第 1 行出现错误:
ORA-01438: 值大于此列指定的允许精度
insert into test values(0.012);
已创建 1 行。
insert into test values(0.0125);
已创建 1 行。
select * from test;
A
----------
.012
.013
3.小结
1)整数部分长度>p-s时,报错;
2)小数部分长度>s时,舍入;
3)s为负数时,对小数点左边的s数字进行舍入;
4)当s>p时,p表示小数后第s位向左最多可以有多少位数字,如果大于p则报错,小数点后s位向右的数字被舍入.
--转自