在网上看到
带小数位和精度的情况。
SQL> create table test_number2(col_char varchar(20),col_num number(1,3)); Table created
精度是1,小数位是3.
可见,精度不是小数位加整数位了。但是精度和小数位倒底什么关系呢?
SQL> insert into test_number2 values('0.111',0.111); insert into test_number2 values('0.111',0.111) ORA-01438: value larger than specified precision allowed for this column
插入3位小数,0.111竟然报错了,说精度不够。
SQL> insert into test_number2 values('0.001',0.001); 1 row inserted
插入0.001时,成功了。
SQL> insert into test_number2 values('0.001',0.0015); 1 row inserted
插入0.0015也成功了。
看看插入的值。
SQL> select * from test_number2; COL_CHAR COL_NUM
-------------------- -------
0.001 0.001
0.0015 0.002
需要注意的是0.0015被舍入为0.002 精度大于小数位
SQL> create table test_number3 (col_char varchar(20), col_number number(5,3)); Table created SQL> insert into test_number3 values('99.899',99.899); 1 row inserted SQL> insert into test_number3 values('99.999',99.999); 1 row inserted SQL> insert into test_number3 values('99.9999',99.9999); insert into test_number3 values('99.9999',99.9999) ORA-01438: value larger than specified precision allowed for this column 注意,当插入99.9999时,系统报错。因为小数位为3位。第四位小数位是9,于是往前入。最终变成100.000.就已经超过了精度。
Number(5,3)可存储的数值最大为99.999. --总结
现在终于有点明白小数位与精度的关系了。
现在应该明白了精度和小数位的关系了吧。
小数位告诉系统保留多少位小数,从哪里开始舍入。
精度舍入后,从舍入的位置开始,数值中允许有多少位(这里怎么理解):我的理解是:小数位四舍五入后,从舍入位置计数位数,但这与(插入0.001时,成功了。
SQL> insert into test_number2 values('0.001',0.0015); 1 row inserted
插入0.0015也成功了。
)矛盾啊(这里的位数是5啊,而精度是1,不是位数不等于精度啊)
找了api看了下:
NUMBER(p,s)where:p is the precision, or the total number of digits. Oracle guarantees the portability of numbers with precision of up to 38 digits.s is the scale, or the number of digits to the right of the decimal point. The scale can range from -84 to 127.Specify an integer using the following form:NUMBER(p)还没看明白,到度精度与小算位有什么关系
带小数位和精度的情况。
SQL> create table test_number2(col_char varchar(20),col_num number(1,3)); Table created
精度是1,小数位是3.
可见,精度不是小数位加整数位了。但是精度和小数位倒底什么关系呢?
SQL> insert into test_number2 values('0.111',0.111); insert into test_number2 values('0.111',0.111) ORA-01438: value larger than specified precision allowed for this column
插入3位小数,0.111竟然报错了,说精度不够。
SQL> insert into test_number2 values('0.001',0.001); 1 row inserted
插入0.001时,成功了。
SQL> insert into test_number2 values('0.001',0.0015); 1 row inserted
插入0.0015也成功了。
看看插入的值。
SQL> select * from test_number2; COL_CHAR COL_NUM
-------------------- -------
0.001 0.001
0.0015 0.002
需要注意的是0.0015被舍入为0.002 精度大于小数位
SQL> create table test_number3 (col_char varchar(20), col_number number(5,3)); Table created SQL> insert into test_number3 values('99.899',99.899); 1 row inserted SQL> insert into test_number3 values('99.999',99.999); 1 row inserted SQL> insert into test_number3 values('99.9999',99.9999); insert into test_number3 values('99.9999',99.9999) ORA-01438: value larger than specified precision allowed for this column 注意,当插入99.9999时,系统报错。因为小数位为3位。第四位小数位是9,于是往前入。最终变成100.000.就已经超过了精度。
Number(5,3)可存储的数值最大为99.999. --总结
现在终于有点明白小数位与精度的关系了。
现在应该明白了精度和小数位的关系了吧。
小数位告诉系统保留多少位小数,从哪里开始舍入。
精度舍入后,从舍入的位置开始,数值中允许有多少位(这里怎么理解):我的理解是:小数位四舍五入后,从舍入位置计数位数,但这与(插入0.001时,成功了。
SQL> insert into test_number2 values('0.001',0.0015); 1 row inserted
插入0.0015也成功了。
)矛盾啊(这里的位数是5啊,而精度是1,不是位数不等于精度啊)
找了api看了下:
NUMBER(p,s)where:p is the precision, or the total number of digits. Oracle guarantees the portability of numbers with precision of up to 38 digits.s is the scale, or the number of digits to the right of the decimal point. The scale can range from -84 to 127.Specify an integer using the following form:NUMBER(p)还没看明白,到度精度与小算位有什么关系
解决方案 »
- 求SQL
- 如何设置Oracle某个角色失效
- oracle两个表连接怎么写比较好
- 同时安装Oracle devoloper suit 10 与Oracle 10数据库的问题
- oracle的job中怎样写每月的5日执行一个作业的代码?
- 关于Oracle中的特殊字符“&”(&)
- 应用程序安装在WIN2003,oracle安装在LINUX上面,为什么应用程序不能连接到数据库呢呢?难道和我的数据库OracleServiceeasdbs.longmay.com.c
- 存储命令为什么不可以用哪??
- 数据库中多字段匹配一个条件
- 做一个数据库管理员要什么样的资格,或是什么层次才能胜任?
- drop table 出错!!!!!!!!!1111
- 高分请教大侠一个问题![100]
表示,这个数最大是10位,其中整数位5位,小数位5位
然后插入0.003那肯定报错
前面的1表示数字最多一位,0.003有四位
要写成number(4,3)才能插入
SQL> insert into test_number2 values('0.001',0.001); 1 row inserted
插入0.001时,成功了。
-------------------
Typ=2 Len=2: 191,11scott@ORA1> select dump(0.005) from dual;DUMP(0.005)
-------------------
Typ=2 Len=2: 191,51scott@ORA1> select dump(0.111) from dual;DUMP(0.111)
----------------------
Typ=2 Len=3: 192,12,11
当number(n,m)n<m时
(m-n)位必须是0,精度是取到m位的。SQL> create table aaa (a number(2,6));
Table created
SQL> insert into aaa values(0.00123);
insert into aaa values(0.00123)
ORA-01438: 值大于为此列指定的允许精度
SQL> insert into aaa values(0.0000123);
1 row inserted
SQL> insert into aaa values(0.0000123345345);
1 row inserted