Introduction to three basic types of Oracle numbers

Source: Internet
Author: User

Three basic Oracle Number types of Oracle numbers: NUMBER, BINARY_INTENER, and PLS_INTEGER. The main function of NUMBER is to describe related integers or real numbers, but PLS_INTEGER and BINARY_INTENER can only describe integers.

NUMBER is stored in decimal format, which is easy to store, but in computing, the system automatically converts it into binary for calculation. It is defined as NUMBER (P, S), P is precision, the maximum is 38 BITs, S is the scale range, can be in the range of-84127. For example, NUMBER (5, 2) can be used to store values that represent-999.99999.99. P and S can be omitted in definition, such as NUMBER (5) and NUMBER;

BINARY_INTENER is used to describe the signed integer that is not stored in the database but must be used for calculation. It is expressed as a binary complement of 2. This type of Oracle Number is often used in cyclic counters.

The only difference between PLS_INTEGER and BINARY_INTENER is that when computing overflow occurs, BINARY_INTENER variables will be automatically assigned to a NUMBER type without error. PLS_INTEGER variables will have errors.

☆Number can be used to store 0, positive, and negative fixed points, or floating point numbers in the Oracle Number type. The data range can be 1.0*10 (-130) -- 9.99*10 (125) {38 9 followed by 88 0} Oracle numbers. When the value of the mathematical expression in Oracle is greater than or equal to 1.0*10 (126), Oracle Reports an error.

The data declaration of Number is as follows:

1) Number (p, s) declares that a specific Number of points p (precision) is precise, and s (scale) indicates the Number of Oracle numbers on the right of the decimal point. The maximum precision is 38, the range of scale value is-84 to 127.

2) Number (p) declares an integer equivalent to Number (p, 0)

3) Number declares that the precision of a floating point Number is 38. Note that the scale value is not applied. That is to say, scale cannot be simply understood as 0 or another Number.

The precision (p) and Scale (s) of the number of points follow the following rules:

When s> 0 (s indicates the number of digits on the right of the decimal point ):

When the length of an integer is greater than p-s, Oracle Reports an error.

When the length of the fractional part of A number is greater than s, Oracle will round.

When s is <0 (s indicates the number of digits on the left of the decimal point ):

Oracle rounds the s number to the left of the decimal point.

When s> p, p indicates the maximum number of Oracle numbers to the left after the decimal point. If it is greater than p, Oracle Reports an error, the number s after the decimal point is rounded to the right, for example:

Value --> Datatype --> Stored Value

123.2564 --> NUMBER --> 123.2564 (unlimited)

1234.9876 --> NUMBER (6, 2) --> 1234.99 (precise to two digits after the decimal point)

12345.12345 --> NUMBER (6, 2) --> Error (length of valid digits on the left of the decimal point is 5 + Length of valid Oracle digits on the right of the decimal point 2> precision 6)

1234.9876 --> NUMBER (6) --> 1235 (equivalent to NUMBER (6, 0 ))

12345.345 --> NUMBER (5,-2) --> 12300 (two digits on the left of the decimal point are rounded down)

12345678 --> NUMBER (5,-2) --> Error (8-2> 5)

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

The above content is an introduction to the Oracle digital type. I hope you will get some benefits.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.