在网上看到
带小数位和精度的情况。
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)还没看明白,到度精度与小算位有什么关系
解决方案 »
- Oracle的锁有几种
- ORACLE 创建包头和包体
- oracle10.2,"启动 Database Control 时出错"日志如下,求解决方法!
- 求教:跨库查询需要知道对方数据库的什么信息,具体开发起来难点都有那些?
- 请问,在oracle中的统计值有什么用?
- oracle8.1.7的连接问题,紧急!!!!!!!!!!!多谢
- 用SQL*Plus创建存储过程,提示“警告: 创建的过程带有编译错误。”,怎样让它显示详细的出错信息?
- oracle下如何想数据库插入图片?
- 如何启动远程数据库
- 在ORACLE的过程中,我创建一个表,在存储过程中我怎么样才能调用这个表??
- 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