This article is about ORALCE's analysis of the NUMBER type storage method and attempts to explain the designer's initial intention.
I recently read a lot of descriptions about ORACLE data storage, and I don't feel familiar with it. So I have read many articles and I have figured out several simple data types.
Number Type
ORACLE's number storage is first converted according to certain rules and then stored in hexadecimal format (the actual storage is of course binary, but what we see in dump is hexadecimal.
The number type stored in the ORACLE database contains three parts: HEAD, DATA, and symbol bit.
For positive numbers, the symbol bit is omitted. For 0, There is only 80.
First, let's look at several storage examples. We can use
SELECTDUMP(89,16)FROMDual |
To see the actual storage result of ORACLE for number type: Typ = 2 Len = 2:C1, 5a
Of course, if we want to see decimal, we use
SELECTDUMP(89,10)FROMDual |
Typ = 2 Len = 2:193, 90
123, C2, 2, 18
123.123 à C2, 2, 18, D, 1F
0 à 80
-123 * 3D, 64, 4E, 66
-0.123 à 3F, 59, 47, 66
The HEAD part is a byte of 8 bits, indicating its size. Of course, it also includes positive and negative values, that is, the C2, 3D we see earlier.
Because when designing this storage format, we want to express all the numbers in hexadecimal format 00-FF, so in order to encode symmetry, we first divide the number into positive and negative values, so we use the intermediate position 80 of 00-FF, that is, the decimal value 128 indicates 0, and the HEAD part is smaller than 80, that is, a negative number. If the value is greater than 80, it is a positive number.
In addition, A number can be expressed as (+/-) A. B * 10 ^ (+-) C, plus and minus A. B * 10 plus and minus C power.
Therefore, ORACLE checks 00-80 and 80-FF again.
00-3E indicates x <=-1
3F-7F indicates-1 <x <0
81-C0 indicates 0 <x <1
C1-FF represents 1 <= x
Then, let's look at the data section. ORACLE stores two decimal digits, for example, 1234 and ORACLE stores 12 and 34 respectively. therefore, you only need to encode (+-) 1-99
1-99 is expressed as 2-100 in hexadecimal 2-64 format, respectively.X = Y-1,
-1--99 is represented as 100-2 in hexadecimal 64-2.X = y-101
The number of digits is represented by the difference of 3E and C1 (62,193) in decimal notation (for convenience. as for the symbol bit, some people on the Internet say it is to facilitate sorting, and the encoding 66 (102) is not used for (+-) 1-99.
For example, 123, we can see that (100 + 23), there is a hundred more digits than 1, so the HEAD is 193 + 1 = 194
The data part is represented by (2, 24), that is (, 2, 24), and converted to hexadecimal format (C2, 2, 18)
123.123, we see (100+ 23 + 0.12 + 0.0030), the same HEAD part is 194
The data is partially (,), so it is (C2, D, 1F)
-123, we can see (-100-23), one hundred more than 1, so the HEAD is 62-1 = 61
Data (64, 78), so it is (3D, 64, 4E, 66)
-0.123, we can see (-0.12-0.0030), the highest bit ratio-1 is one percentile, so the HEAD is 62 + 1 = 63
The data part is (), so it is (3F, 59, 47, 66)
The inverse process is easy to know.