create table t(msg varchar2(10),num_col number(5,-2));
insert into t(msg,num_col) values('123.45',123.45);
insert into t(msg,num_col) values('123.45',123.456);
insert into t(msg,num_col) values('1234567',123456);
insert into t(msg,num_col) values('1234567',1234567);select * from t;MSG        NUM_COL
---------- -------
123.45         100
123.45         100
1234567     123500
1234567    1234600insert into t(msg,num_col) values('1234567',12345678)
ORA-01438: value larger than specified precision allows for this column书上这么说:
number (p , s)
p:精度,或总位数
s:小数位数我上面定义的是num_col number(5,-2),也就是能存5位的整数。
但是:
insert into t(msg,num_col) values('1234567',1234567)能成立,
insert into t(msg,num_col) values('1234567',12345678)就不成立了,也就是说我的num_col列能存的位数是7位数。
那么具体怎么计算这个number类型的数据列能存的数的位数呢?

解决方案 »

  1.   

    http://www.cublog.cn/u/19782/showart_207809.html
      

  2.   

    good !
    楼主 蛮有专研精神的
      

  3.   


    问题解决了,谢谢各位!
    2. s<0
    精确到小数点左边s位,并四舍五入。然后检验有效数位是否<=p+|s|补充一点:
    上面所说的四舍五入是指,将数值舍入与之最接近的100:
    12345 舍为 12300
    12456 舍为 12500
      

  4.   

    Negative scale is the number of significant digits to the left of the decimal point, to but not including the least significant digit. For negative scale the least significant digit is on the left side of the decimal point, because the actual data is rounded to the specified number of places to the left of the decimal point.