What is the default Precision and Scale for a Number in Oracle?

前端 未结 6 659
时光说笑
时光说笑 2020-12-01 07:13

When creating a column of type NUMBER in Oracle, you have the option of not specifying a precision or scale. What do these default do if you don\'t specify them?

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-12-01 07:34

    Oracle stores numbers in the following way: 1 byte for power, 1 byte for the first significand digit (that is one before the separator), the rest for the other digits.

    By digits here Oracle means centesimal digits (i. e. base 100)

    SQL> INSERT INTO t_numtest VALUES (LPAD('9', 125, '9'))
      2  /
    
    1 row inserted
    
    SQL> INSERT INTO t_numtest VALUES (LPAD('7', 125, '7'))
      2  /
    
    1 row inserted
    
    SQL> INSERT INTO t_numtest VALUES (LPAD('9', 126, '9'))
      2  /
    
    INSERT INTO t_numtest VALUES (LPAD('9', 126, '9'))
    
    ORA-01426: numeric overflow
    
    SQL> SELECT DUMP(num) FROM t_numtest;
    
    DUMP(NUM)
    --------------------------------------------------------------------------------
    Typ=2 Len=2: 255,11
    Typ=2 Len=21: 255,8,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,79
    

    As we can see, the maximal number here is 7.(7) * 10^124, and he have 19 centesimal digits for precision, or 38 decimal digits.

提交回复
热议问题