Oracle NUMBER When both p and s are omitted, the currently representable data is floating point, which can store positive and negative numbers, zero values, floating point numbers, etc.

The NUMBER data type is widely used in Oracle. It can store zero values, positive and negative numbers, and fixed-length numbers. There are several concepts to be clear about this data type, otherwise it is easy to confuse. The specific description is given below.

 

1. The range and storage space can be expressed
    from 1.0 x 10-130 to 1.0 x 10126 (not included). If the expression or value is greater than 1.0 x 10126, Oracle will return an error message
    . The storage space required is 1 to 22 bytes
 
2. Number type notation
    NUMBER (p, s) P and S optional

    Where precision represents the total length of the number, and scale represents several decimal places.
    Precision is also called precision, which is the total number of digits in the exponent. By default, the precision is 38 digits, and the value range is 1 to 38.
    scale is the number of decimal places, that is, the number of digits to the right of the decimal point in the number. It ranges from -84 to 127 and can determine the rounding rules. If we do not specify the value of scale, the default is 0.
    You cannot use constants or variables to specify the length and precision of NUMBER. The maximum length of the NUMBER type is 38 bits.
    If you do not specify the maximum length of the NUMBER type, the default length or the maximum length supported by the system will be used.
    The precision and number of decimal places will not affect how the data is stored on disk, but only what values ​​are allowed and how the values ​​are rounded.

    For example, the precision of the number 123.45 is 5, and the number of decimal places is 2.
  
    The following analysis of p and s
    p> 0, analysis of s points in two cases:
  
  a. S> 0
    accurate to the right of the decimal point s digits, and rounded. Then check whether the significant digits are <= p; if s> p, at least sp zeros are filled to the right of the decimal point.
  
  b. s <0 is
    accurate to the s digit to the left of the decimal point, and rounded. Then check whether the significant digits are <= p + | s |
  
    (significant digits: counted from the first number on the left that is not 0).
  
    For floating-point numbers, the accuracy problem is not considered.
  
  C, indicating an integer.
    When the value of s is omitted, it is equivalent When s is equal to 0, it means that the integer
  
    NUMBER (p) is equivalent to NUMBER (p, 0)
  
  c, floating point type
    When both p and s are omitted, the current representable data is floating point type, which can store positive and negative numbers, zero
    Examples of values, floating point numbers, etc . :
    Value Datatype Stored Value
    123.2564 NUMBER 123.2564
    1234.9876 NUMBER (6,2) 1234.99              
    12345.12345 NUMBER (6,2) Error                
    1234.9876 NUMBER (6) 1235                 
    12345.345 NUMBER (5, -2) 12300                
    1234567 NUMBER (5, -2) 1234600              
    12345678 NUMBER (5, -2) Error                
    123456789 NUMBER (5, -4) 123460000            
    1234567890 NUMBER (5, -4) Error                
    12345.58 NUMBER (*, 1) 12345.6              
    0.1 NUMBER (4,5) Error                
    0.01234567 NUMBER (4,5) 0.01235              
    0.09999 NUMBER (4,5) 0.09999              
    0.099996 NUMBER (4,5) Error
——————————————— -
Disclaimer: this article is the original article CSDN bloggers "Leshami", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https://blog.csdn.net/robinson_0612/java/article/details/8153826

Guess you like

Origin www.cnblogs.com/kakaisgood/p/12674423.html