Oracle中number类型详解

1、Oracle总number类型的用法是 number[({p},[s])]其中p表示整个数的位数,s表示小数点的位数,比如: number(5,2)表示这个数最多有5位(不包括小数点在内),2表示小数点后有两位小数

2、p的最大38是,s的范围是-84到127。

3、用法:

 (1)p>s>0 总位数是p,小数位数是s,整数部分位数是p-s

 (2)p=s=0可以表示任何数,只要这个数在范围内就行了,这个数可以是整数,浮点数都行

 (3)p>0 s=0表示整数

 (4) p>0 s<0 其中s表示在小数点右边的0的个数,并且从这个位置开始四舍五入,例如1234567 是number(5,-2)类型,则结果是1234600

 (5)p>0 s>0 p<s则在小数点的右边有s-p个0,同时保留小数点的个数是s个

  


Value Datatype Stored Value Explanation
123.2564 NUMBER 123.2564 The range and precision are set to the maximum, so the datatype can store any value.
1234.9876 NUMBER(6,2) 1234.99 Since the scale is only 2, the decimal part of the value is rounded to two digits.
12345.12345 NUMBER(6,2) Error The range of the integer part is only from –9999 to 9999.
123456 NUMBER(6,2) Error The precision is larger than specified; the range is only from –9999 to 9999.
1234.9876 NUMBER(6) 1235 The decimal part is rounded to the next integer.
123456.1 NUMBER(6) 123456 The decimal part is rounded.
12345.345 NUMBER(5,-2) 12300 The negative scale rounds the number <s> digits left to the decimal point. –2 rounds to hundreds.
1234567 NUMBER(5,-2) 1234600 Rounded to the nearest hundred.
12345678 NUMBER(5,-2) Error Outside the range; can have only five digits, excluding the two zeros representing hundreds, for a total of seven digits: (s – (–p) = s + p = 5 + 2 = 7).
123456789 NUMBER(5,-4) 123460000 Rounded to the nearest 10,000.
1234567890 NUMBER(5,-4) Error Outside the range; can have only five digits, excluding the four trailing zeros.
12345.58 NUMBER(*, 1) 12345.6 The use of * in the precision specifies the default limit (38).
0.1 NUMBER(4,5) Error Requires a zero after the decimal point (5 – 4 = 1).
0.01234567 NUMBER(4,5) 0.01235 Rounded to four digits after the decimal point and zero.
0.09999 NUMBER(4,5) 0.09999 Stored as it is; only four digits after the decimal point and zero.
0.099996 NUMBER(4,5) Error Rounding this value to four digits after the decimal and zero results in 0.1, which is outside the range.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值