Oracle Data Type ----- (digital format)

Source: Internet
Author: User

Any real number can be expressed as: S = A. B * 10n (N power of 10 ). Then we only need to store A. B (Data Part), n (highest bit. However, oracle also stores the symbol bit (which is required for negative numbers ).
Create table test_number (num_col number );
SQL> INSERT INTO TEST_NUMBER VALUES (0 );
 
1 row inserted
 
SQL> INSERT INTO TEST_NUMBER VALUES (1 );
 
1 row inserted
 
SQL> INSERT INTO TEST_NUMBER VALUES (2 );
 
1 row inserted
 
SQL> INSERT INTO TEST_NUMBER VALUES (25 );
 
1 row inserted
 
SQL> INSERT INTO TEST_NUMBER valuees (123 );
 
1 row inserted
 
SQL> INSERT INTO TEST_NUMBER valuees (4100 );
 
1 row inserted
 
SQL> INSERT INTO TEST_NUMBER valuees (132004078 );
 
1 row inserted
 
SQL> INSERT INTO TEST_NUMBER valuees (2.01 );
 
1 row inserted
 
SQL> INSERT INTO TEST_NUMBER valuees (0.3 );
 
1 row inserted
 
SQL> INSERT INTO TEST_NUMBER valuees (0.00000125 );
 
1 row inserted
 
SQL> INSERT INTO TEST_NUMBER valuees (115.200003 );
 
1 row inserted
 
SQL> INSERT INTO TEST_NUMBER VALUES (-1 );
 
1 row inserted
 
SQL> INSERT INTO TEST_NUMBER VALUES (-2 );
 
1 row inserted
 
SQL> INSERT INTO TEST_NUMBER VALUES (-20032 );
 
1 row inserted
 
SQL> INSERT INTO TEST_NUMBER VALUES (-234.432 );
 
1 row inserted
 
SQL> COMMIT;
 
Commit complete
 
SQL> SELECT NUM_COL, DUMP (NUM_COL, 16) D_NUMBER FROM TEST_NUMBER;
 
NUM_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
4100 Typ = 2 Len = 2: c2, 2a
132004078 Typ = 2 Len = 6: c5, 4f
2.01 Typ = 2 Len = 3: c1, 3, 2
0.3 Typ = 2 Len = 2: c0, 1f
1.25E-6 Typ = 2 Len = 3: be, 2, 1a
115.200003 Typ = 2 Len = 6: c2, 4
-1 Typ = 2 Len = 3: 3e, 64, 66
-2 Typ = 2 Len = 3: 3e, 63,66
-20032 Typ = 2 Len = 5: 3c
-234.432 Typ = 2 Len = 6: 3d, 3a
 
15 rows selected
 
0: No data part. Only one highest bit is stored.
1: C1 indicates the highest bit. Why is that ??
A positive number and a negative number have the same value range. Therefore, the maximum value of a positive number is greater than 80, and the maximum value of a negative number is less than 80.
However, positive numbers are divided into numbers greater than 1 and decimal places, and have the same value range.
 
The calculation formula is as follows:
SQL> select round (to_number ('ff ', 'xx')-to_number ('80', 'xx')/2 + to_number ('80 ', 'xx') + 1 from dual;
 
ROUND (TO_NUMBER ('ff ', 'xx')-
------------------------------
193
 
SQL> select to_char ('20140901', 'xx') from dual;
 
TO_CHAR ('123', 'xx ')
-------------------
C1
Therefore, the highest number of BITs is C1.
Then the highest bits represent C2, the highest bits represent C3, the highest bits represent C0, and the highest bits represent C0, and so on.
Why?
Each Oracle byte represents two digits, and the difference between two digits is 100 (that is, 10 square ). Therefore, the highest representation of a hundred bits is C2.
 
But why does oracle use 0x2 to represent 1 ???
For this 2-digit number, it may be 0 ~ There are 100 possibilities in 99, and the problem lies in 0. Oracle is implemented in C language at the underlying layer. We know that binary 0 is used as the string terminator in C language. Oracle uses 0x1 to avoid this problem, and so on, 0x64 indicates 99.
 
-1 Typ = 2 Len = 3: 3e, 64, 66. Why is the highest bit 3e ??
Because negative numbers and positive numbers are opposite to each other. The maximum number of BITs is 255, and the total number of BITs is 66. Therefore, the highest bitwise of-1 is 3e.
SQL> select to_char ('20140901', 'xx') from dual;
 
TO_CHAR ('123', 'xx ')
-------------------
C1
 
SQL> select to_number ('3e ', 'xx') from dual;
 
TO_NUMBER ('3e ', 'xx ')
--------------------
62
The negative data is expressed in 65 to 2.

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.