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

 

 http://space.itpub.net/519536/viewspace-557312

 

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

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

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 --
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值