You are on page 1of 7

This article describes how the NUMBER types of data and stored in the database.

Oracle NUMBER types are the most by three parts, three parts are the highest that bit, the data part of the sign bit. Which contains the sign bit negative, a positive number does not include the sign bit. In addition, the value 0 is special, it only contains the highest value bits of a 80-bit, no data part. The maximum number of bits are bit larger than 80, the highest bit of said bit negative number less than 80. One of the highest positive number is a bit, then the highest bit that bit of C1, hundred, million bits followed by C2, C3, percentile, followed by extreme as C0, BF. The highest bit of a negative number a bit if that bit is the highest bit 3E, hundred, ten thousand were 3D, 3C, percentile, extreme ranked as 3F, 40. Each one of said data portion 2 digits. The double-digit may be from 0 to 99, if the data itself is positive, then the binary respectively 1 to 64 said that if the data itself is negative, then use the binary 65-2 said. Sign bit with the 66 said. These are my top by DUMP summed up the results, these relations for the constants mentioned above, Oracle reason for this choice is reasonable, we can later be derived based on examples, and will further explain why this approach said. Means listed here so that people first of NUMBER data types have a general understanding. Below we detail through an example:

SQL> CREATE TABLE TEST_NUMBER (NUMBER_COL NUMBER); Table has been created. SQL> INSERT INTO TEST_NUMBER VALUES (0); Has created a line.

SQL> INSERT INTO TEST_NUMBER VALUES (1); Has created a line. SQL> INSERT INTO TEST_NUMBER VALUES (2); Has created a line. SQL> INSERT INTO TEST_NUMBER VALUES (25); Has created a line. SQL> INSERT INTO TEST_NUMBER VALUES (123); Has created a line. SQL> INSERT INTO TEST_NUMBER VALUES (4100); Has created a line. SQL> INSERT INTO TEST_NUMBER VALUES (132004078); Has created a line. SQL> INSERT INTO TEST_NUMBER VALUES (2.01); Has created a line. SQL> INSERT INTO TEST_NUMBER VALUES (0.3); Has created a line. SQL> INSERT INTO TEST_NUMBER VALUES (0.00000125); Has created a line. SQL> INSERT INTO TEST_NUMBER VALUES (115.200003); Has created a line. SQL> INSERT INTO TEST_NUMBER VALUES (-1); Has created a line. SQL> INSERT INTO TEST_NUMBER VALUES (-5); Has created a line. SQL> INSERT INTO TEST_NUMBER VALUES (-20032); Has created a line. SQL> INSERT INTO TEST_NUMBER VALUES (-234.432); Has created a line. SQL> COMMIT; Submit completed.

SQL> COL D_NUMBER FORMAT A50 SQL> SELECT NUMBER_COL, DUMP (NUMBER_COL, 16) D_NUMBER FROM TEST_NUMBER; NUMBER_COL D_NUMBER ---------- ---------------------------------------- ---------0 Typ = 2 Len = 1: 80 1 Typ = 2 Len = 2: c1, 2 2 Typ = 2 Len = 2: c1, 3 25 Typ = 2 Len = 2: c1, 1a 123 Typ = 2 Len = 3: c2, 2,18 4100 Typ = 2 Len = 2: c2, 2a 132004078 Typ = 2 Len = 6: c5, 2,21,1,29,4 f 2.01 Typ = 2 Len = 3: c1, 3,2 .3 Typ = 2 Len = 2: c0, 1f .00000125 Typ = 2 Len = 3: be, 2,1 a 115.200003 Typ = 2 Len = 6: c2, 2,10,15,1,4 -1 Typ = 2 Len = 3: 3e, 64,66 -5 Typ = 2 Len = 3: 3e, 60,66 -20032 Typ = 2 Len = 5: 3c, 63,65,45,66 -234.432 Typ = 2 Len = 6: 3d, 63,43,3 a, 51,66 Has selected 15 lines.

The following examples are based on the results, described on each line. First, note two fundamental points. DUMP function returns DUMP TYPE = 2 that the data type is NUMBER, LENGTH = N, said value stored in the database length is N. 1.DUMP (0) the result is 0x80, mentioned earlier, that bit 0 is only high, no data bits. Since 0 special, neither positive nor are negative, so that bit by using the 80 expressed high enough and will not conflict with other data, Oracle will be considered for space-saving save the data

portion of the back. But why choose 0x80 Oracle said 0? We know the positive and negative numbers opposite each other, every positive number has a corresponding negative. So that if we want to use the numerical code, said encoding positive and negative numbers should be half and half, so as to ensure that the Oracle data range that is reasonable. The binary code is 0x80 1000 0000, exactly half the maximum value a byte encoding, therefore, Oracle selected to represent 0 0x80 is very justified. 2.DUMP (1) the result is 0xc102, 0xc1 expressed the highest level a bit, 0x2 that value is 1. First, Oracle said a bit C1 Why it? In fact, the truth and just about the same. Using scientific notation, and any real number S can be described as AB 10 n , said the integer part of A, B representing the fraction part and exponent part N said 10. When S is greater than 1, N greater than or equal 0, S is less than 1, N is less than 0. That is, the way in using index, N is greater than 0 and N is less than 0 when the case is about half and half, Oracle most widely expressed. Therefore, Oracle chose to express a bit C1 is the highest bit of the situation. SQL> SELECT TO_CHAR (ROUND (TO_NUMBER ('81 ',' XXX ') + (TO_NUMBER (' FF ',' XXX ') - TO_NUMBER ('81', 'XXX') + 1) / 2), 'XX' ) FROM DUAL;

TO_ --C1

Why is that an ORACLE using 0x2 instead of 0x1 that a direct use of it? Oracle 2-digit for each byte, so for the 2-digit, there may be 0 to 99 of 100 possible, the problem is 0 here. Oracle is the underlying C

language, we know that a binary 0 in the C language as a string terminator, Oracle To avoid this problem, the use of a 0x1 that 0, and so on, using the 0x64 that 99. 3.DUMP (2) the result is 0xc103. 4.DUMP (25) The result is 0x c11a. Mentioned earlier, the data portion is the smallest unit of two saved. So for 25, the highest bit that bit is still a bit, a bit on the value is 25, according to the rules introduced above, 25 in the storage for the 0xc11a. SQL> SELECT TO_CHAR (25 + 1, 'xx') FROM DUAL;

TO_ --1a

5.DUMP (123) The result is 0x c20218. Because up to a hundred 123-bit, so the maximum bit that bit 0xc2, is one hundred, with the 0x02, said bits is 23, said with a 0x18. 6.DUMP (4100) The result is 0x c22a. Note that if the number of the last few bits on if it is 0, Oracle will not be considered for space-saving storage. For example: 4100 Save hundreds on 41,12000000 only save one hundred bits stored on the 12,512000 million bits only on 51 and 20 on the hundred. 7. DUMP (132 004 078) the result is 0xc5022101294f. Highest level is one hundred million, so with 0xC5 that is 1 billion bits, said with a 0x02, one hundred bits is 32, said with a 0x21, with a million bits is 0, 0x01, said one hundred is 40, said with a 0x29, bits said on 78 with 0x4F. Note: the digital intermediate on 0 can not be omitted.

8.DUMP (2.01) the result is 0xc10302. With the highest bit is a bit 0xC1 said bits is 2 with a 0x03 that is a percentile expressed by 0x02. Note: The following one is a bit not very bit percentile. 9.DUMP (0.3) The result is 0xc01f. Is the highest percentile, the use of 0xC0 said the 30-percentile is indicated with 0x1F. 10.DUMP (0.00000125) The result is 0xbe021a. Highest point is the millions of bits, with 0xBE said highest said on 1 with 0x02 and 25 with 0x1a said. 11.DUMP (115.200003) The result is 0xc20210150104. 12.DUMP (-1) the result is 0x3e6466. Highest level a bit, with 0x3E, said that a 64-bit is the sign bit is 1,66, that the number is negative. Opposite each other negative and positive, negative, the highest level that corresponds to the opposite position and the number of its highest value is the sum of FF. 1, the highest bit that bit is C1, -1 in the highest bit that bit is 3E. Negative in 1 with 64 said. Negative values in the data and its opposite number is the sum of 0x66, which is the sign bit. Number 1 is expressed by 0x02, 0x64, said with a negative one, the two sum is 0x66. Negative bit more than a logo, use 0x66 said. As the number of that range is 0x01 to 0x64, 0x65 negative of that range to 0x02. Therefore, said the numbers will not appear 0x66 said. 13. DUMP (-5) the result is 0x3e6066. 0x3e is the highest bit is a bit, 0x60, said bits is 5,0 x66 is a sign identifies the place. Add 0xC1 0x3E is 0xFF. Result of adding 0x06 0x60 0x66. 14.DUMP (-20032) The result is 0x3c63654566. Highest is ten thousand, is the number of million bits is 0xC3, a negative million bits is 0x3C. Million bits is 2, use 0x03 expressed positive, negative for the 0x63, one hundred is 0, 0x01, said with positive, negative use of 0x65 that is 32 bits, positive, said with a 0x21, 0x45, said to use negative numbers. 0x66 is a negative number indicates a bit. 15.DUMP (-234.432) The result is 0x3d63433a5166.

According to Oracle's storage characteristics, Oracle also introduced a range of number types. Oracle's concept is described: The following numbers can be stored in a NUMBER column: Positive Numbers in the Range 1 x 10 -130 to 9.99 ... 9 x 10 125 with up to 38 significant digits. Negative Numbers from -1 x 10 -130 to 9.99 ... 99 x 10 125 with up to 38 significant digits. Zero. To derive the following range. See the sign bit, 0xC1 that a bit. SQL> select to_number ('ff', 'xxx') - to_number ('c1', 'xxx') from dual; TO_NUMBER ('FF', 'XXX')-TO_NUMBER ('C1', 'XXX') ------------------------------------------62 Because Oracle is two, two stores, so the highest level is equivalent to 62 2 = 124, and the highest maximum value is 99, so the maximum positive 9.999 ... ... 10 125 . SQL> select to_number ('c1', 'xxx') - to_number ('80 ',' xxx ') from dual; TO_NUMBER ('C1', 'XXX')-TO_NUMBER ('80 ',' XXX ') ------------------------------------------65 Highest equivalent of 65 2 = 130, so is the minimum number of 1 10 -130 . Negative and positive numbers in each half of the encoding used, it has the same extreme range.

You might also like