Number of bytes occupied by the Data Type in Oracle

Source: Internet
Author: User

Oracle uses a variable-length storage method to store number data. Each number value is stored in the database in the form of scientific Notation: one byte is used to store the symbol/index, and up to 20 bytes are used to store the ending number. However, the maximum precision of the stored number data is 38 BITs.

For example, 412 is stored in the database in the form of 4.12X10 ^ 2. one byte is used to store index 2, and the other two bytes are used to store numbers, such as 4, 1, and 2, therefore, 412 occupies three bytes in the database.

For the symbol/exponent part, 8th bits are used to represent the numerical value. 0 represents a negative number, and 1 represents a positive number. The remaining 7 digits are used to represent the index. However, the index value must be deducted from the 64-bit value before it is the real index value.

For example, if the value of the symbol/exponent part is 223, its binary value is 11011111. The value 8th is 1, which indicates that the value is positive. In order to determine the exponent value, remove the 8th bits, and the remaining 7 bits 1011111 value is 95. After 64 is deducted, 31 is obtained, this is a real exponential value. \

If the value of the symbol/exponent part is 100, its binary value is 01100100. The value of 8th is 0, which indicates that the value is negative. The value of 01100100 is supplemented to get 10011011, and the value of 8th is removed. The value of 0011011 for the remaining 7 digits is 27. After 64 digits are deducted, get-37, which is the real exponent value.

For the tail part, each value indicates a 100 hexadecimal value. To avoid binary 0, each byte in the tail part is automatically added with 1, therefore, each ending number byte represents a value range of 1-100. In fact, they represent a true value range of 0-99. If it is a negative number, the ending part ends with 102.

The best tool for observing number storage is the dump function, which can display the internal storage value of number in the database to us:

If the dump value of 123456. 789 is:

DUMP (C1)

------------------------------------------

Typ = 2 Len = 6: 195, 13, 35, 57, 79,91

This indicates that the database uses 6 bytes to indicate 123456.789. Each byte is as follows:

1st bytes = 195 --> indicates that the binary value is 11000011.

Indicates that the value is positive, and the index value is 67-64 = 3.

2nd bytes = 13

Because it indicates the ending number, the value is 12 after 1 is subtracted.

3rd bytes = 35

Because it indicates the ending number, after 1 is subtracted, the result is 34.

4th bytes = 57

Because it indicates the ending number, 56 is obtained after 1 is subtracted.

5th bytes = 79

Because it indicates the ending number, after 1 is subtracted, 78 is obtained.

6th bytes = 91

Because it indicates the ending number, 90 is obtained after 1 minus.

We get the index 3, and the value of the ending part is based on 100, so the represented value is:

12x(100 e 2) + 34x(100 e 1) + 56x(100 e 0) + 78x(100 e-1) +

90x(100 e-2) = 123456.789

If the dump value of-123456. 789 is:

DUMP (C1)

------------------------------------------

Typ = 2 Len = 7: 60, 89, 67,45, 102

This indicates that the database uses 6 bytes to indicate 123456.789. Each byte is as follows:

Note: The value ends with 102, indicating that the value is a negative number.

1st bytes = 60 --> indicates that the binary value is 00111100.

The value 0 indicates a negative number. After this value is reversed, it is set to 11000011. If the value is removed from 8th bits, it indicates 67. After 64 bits are deducted, 3 is displayed. The true value of this index is 3.

2nd bytes = 89

Because it indicates the ending number, 88 is obtained after 1 reduction. Because it is a negative number, the real value is 100-88 and 12 is obtained.

3rd bytes = 67

Because it indicates the ending number, the result is 66 After the value is reduced by 1. Because it is a negative number, the actual value is 100-66 and 34.

4th bytes = 45

Because it indicates the ending number, minus 1 to get 44, because it is a negative number, so the real value is 100-44 to get 56

5th bytes = 23

Because it indicates the ending number, 22 is obtained after 1 minus. Because it is a negative number, the real value is 100-22 and 78 is obtained.

6th bytes = 11

Because it indicates the ending number, minus 1 to get 10, because it is a negative number, so the real value is 100-10 to get 90

7th bytes = 102

This indicates that this is the last byte.

We get the index 3, and the value of the ending part is based on 100, so the represented value is:

12x(100 e 2) + 34x(100 e 1) + 56x(100 e 0) + 78x(100 e-1) +

90x(100 e-2) = 123456.789

Because this is a negative number, the real value is-123456.789.

Of course, the space occupied by the value can also be calculated based on the formula:

Number (p, s) occupies the following space:

Length = floor [(p + 1)/2] + 1

Note: If the value is negative, you need to add a byte.

Therefore, your NUMBER (5, 2) occupies the following NUMBER of bytes: floor [(p + 1)/2] + 1 = floor [(5 + 1) /2] + 1 = 3 + 1 = 4

Therefore, if NUMBER () represents an integer and occupies 4 bytes, if NUMBER () represents a negative NUMBER, it occupies 5 bytes.

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.