有关Oracle NUMBER类型定义中precision和scale的测试和总结 _MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 2516 | 回复: 0   主题: 有关Oracle NUMBER类型定义中precision和scale的测试和总结         下一篇 
xiaojiang
注册用户
等级:少尉
经验:345
发帖:77
精华:0
注册:2011-8-31
状态:离线
发送短消息息给xiaojiang 加好友    发送短消息息给xiaojiang 发消息
发表于: IP:您无权察看 2015-6-25 14:17:31 | [全部帖] [楼主帖] 楼主

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位向右的数字被舍入.

--转自 北京联动北方科技有限公司




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论