Detailed explanation of Oracle number type

Introduction

Oracle's number type is more complex and has many restrictions, but it can be easily done with a little skill.

oracle number

Basic Instructions

number(precision,scale)

  1. precision indicates the significant digits in the number, starting from the first non-zero number on the left, the decimal point and negative sign are not counted in the significant digits
  2. The value range of precision is [1,38]
  3. The default value of precision is 38, and number is equivalent to number(38)
  4. If scale is greater than 0, it means that the number is accurate to the right of the decimal point, and number(2,3) means it is accurate to 3 digits to the left of the decimal point.
  5. If scale is less than 0, it means that the number is rounded to the digit to the left of the decimal point, number(3,-2) means four-color five-person to hundreds, 123, becomes 100
  6. The value range of scale is [-84,127]
  7. The default value of scale is 0
  8. The maximum length allowed for the integer part of number is precision-scale
  9. An error occurs when the length of the integer part of number is greater than precision-scale. For example, number(3,2) cannot store 12.34 because the precision is not enough.
  10. When the length of the fractional part of the number is greater than scale, the extra digits in the fractional part will be rounded off, for example, number(3,1), when 3.1415 is stored, 3.1 will be stored.
  11. When the scale is negative, round off the sacle numbers to the left of the decimal point, such as number(5,-3), store 1234567.89, and store the value as 1235000. You can see that 0 does not occupy significant digits.

Here comes the term that goes against first intuition:

When scale is greater than precision, precision indicates the maximum number of digits to the left of the scale digit after the decimal point. If it is greater than p, an error occurs, and the digits after the decimal point s digits to the right are rounded off.

Another way of thinking, another way of speaking, may be easier to understand. When scale is greater than precision, it is only possible that the precision of the fractional part is greater than the precision of the whole number. This number is a decimal, and most of it is 0.00..xx.

For example, number(2,3), the fractional part has 3 digits, but the data can only have two exact digits, so only 0.012 can be stored, and only 12 significant digits can be stored. If it is 0.12, it cannot be stored. Because 0.12 three significant digits is 0.120, so many digits cannot be saved.

error prone

  1. number(8), it is no problem to store 1234567.89, because the decimal place is not defined, the decimal place is discarded reasonably
  2. number(6), cannot store 1234567.89, although no decimal places are stored, but the integer bits are not enough
  3. number(9,3), cannot store 1234567.89, although the precision is 9 bits, it defines that the decimal place occupies 3 bits, only 6 integer bits, and 1234567 has 7 bits
  4. number(7,2), cannot store 1234567.89, nothing to say, not enough precision, 7 digits are not enough to store 9 digits
  5. number(2,3), can not store 0.23, the decimal part has 3 significant digits, 0.230, the precision is only 2 digits, not enough to store

Number and MySQL data types

MySQL data types size in bytes range - signed range - unsigned oracle number
tinyint 1 bytes (-128,127) (0,255) number(3)
smallint 2 bytes (-32 768,32 767) (0,65 535) number(5)
mediumint 3 bytes (-8 388 608,8 388 607) (0,16 777 215) number(8)
integer 4 bytes (-2 147 483 648,2 147 483 647) (0,4 294 967 295) number(10)
bigint 8 bytes (-9,223,372,036,854,775,808,9 223 372 036 854 775 807) (0,18 446 744 073 709 551 615) number(20)

Oracle's number is very similar to MySQL's decimal, but the data types are more finely distinguished, which can make better use of storage space and improve performance.

{{o.name}}
{{m.name}}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324131799&siteId=291194637