您的位置:首页 > 数据库 > Oracle

【NUMBER】有关Oracle NUMBER类型定义中precision和scale的测试和总结

2011-12-26 10:33 429 查看
http://space.itpub.net/519536/viewspace-557312

【NUMBER】有关Oracle NUMBER类型定义中precision和scale的测试和总结

上一篇 /

下一篇 2010-09-11 22:47:28 / 个人分类:SQL

查看( 245 ) /
评论( 0 ) /
评分( 0 /
0 )
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位向右的数字被舍入.

Good luck.

secooler

10.09.11

-- The End --
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: