數字類型包含number,integer,float...oracle內部標識爲2
數字類型在oracle內部是以單字節的數字爲存儲的變長數組
數字類型在oracle文件中的存儲格式爲:
類型 <[長度]>,符號/指數位 [數字1,數字2,數字3,......,數字20]
各位的含義如下:
1.類型: Number型,Type=2 (類型代碼可以從Oracle的文檔上查到)
2.長度:指存儲的字節數
3.符號/指數位
在存儲上,Oracle對正數和負數分別進行存儲轉換:
正數:加1存儲(爲了避免Null)
負數:被101減,如果總長度小於21個字節,最後加一個102(是爲了排序的需要)
指數位換算:
If the first byte is greater than or equal to 128, then the number is positive and the
exponent is:
exponent = first byte - 128 - 65 = first byte - 193
If the first byte is less than 128, then the number is negative and the exponent is:
exponent = (255 - first byte) - 128 - 65 = 62 - first byte
4.從<數字1>開始是有效的數據位
從<數字1>開始是最高有效位,所存儲的數值計算方法爲:
將下面計算的結果加起來:
每個<數字位>乘以100^(指數-N) (N是有效位數的順序位,第一個有效位的N=0)
5. 正數計算舉例:
SYS@huiche>select dump(123456.783,16) from dual;
DUMP(123456.783,16)
----------------------------------------------------------
Typ=2 Len=6: c3,d,23,39,4f,1f
SYS@huiche>
<指數>: 195 - 193 = 2
• 數字
0xd = 13(dec) -1 = 12 > 12 * 100^2 = 120000
0x23 = 35(dec) -1 = 34 > 34 * 100^1 = 3400
0x39 = 57(dec) -1 = 56 > 56 * 100^0 = 56
0x4f = 79(dec) -1 = 78 > 78 * 100^-1 = .78
0x5b = 31(dec) -1 = 30 > 90 * 100^-2 = .003
sum = 123456.783
因爲第一個字節(0xc3)大於128, 所以爲正數
6.負數計算舉例:
SYS@huiche>select dump(-123456.783,16) from dual;
DUMP(-123456.783,16)
------------------------------------------------------------------
Typ=2 Len=7: 3c,59,43,2d,17,47,66
SYS@huiche>
指數 => 0x3c= 62(dec) - 60 = 2
• 數字
0x59 = 89(dec): 101 - 89 = 12 > 12 * 100^2 = 120000
0x43 = 67(dec): 101 - 67 = 34 > 34 * 100^1 = 3400
0x2d = 45(dec): 101 - 45 = 56 > 56 * 100^0 = 56
0x17 = 23(dec): 101 - 23 = 78 > 78 * 100^-1 = .78
0xb = 11(dec): 101 - 71 = 30 > 30 * 100^-2 = .003
sum = 123456.783 (-)
• 最後一個字節不計算在內 0x66 = 102(dec) ,第一個字節(0x3c)小於128, 所以爲負數
7.0的存儲數字是80
SYS@huiche>select dump(0,16) from dual;
DUMP(0,16)
------------------------------
Typ=2 Len=1: 80
SYS@huiche>