给团队内部做的一个Oracle 数据类型分享,主要是关于Oracle数据类型一些内部存储结构及性能介绍。
http://www.slideshare.net/yzsind/oracle-4317768
以下是PPT中unDumpNumber函数的全部代码:
create or replace function unDumpNumber(iDumpStr varchar2) return number is
TYPE ByteArray IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
Bytes ByteArray;
Result number;
i integer;
pos1 integer;
pos2 integer;
pos3 integer;
vlength integer;
begin
result := 0;
pos1 := instr(iDumpStr, 'Len=') + 4;
pos2 := instr(iDumpStr, ':');
vlength := substr(iDumpStr, pos1, pos2 - pos1);--get length
i := 0;
pos2 := pos2 + 1;
--将dump的字符串填充到数组中
for i in 0..vlength-1
loop
pos3 := instr(iDumpStr, ',', pos2);
if pos3>0 then
Bytes(i) := trim(substr(iDumpStr, pos2, pos3 - pos2 ));
else
Bytes(i) := trim(substr(iDumpStr, pos2));--最后1字节
end if;
pos2 := pos3 + 1;
end loop;
--还原NUMBER
if Bytes(0) = 128 then --128表示0
result := 0;
elsif Bytes(0) > 128 then --大于128表示正数
for i in 1 .. vlength - 1 loop
result := result +
(Bytes(i) - 1) * power(100, (Bytes(0) - 193) - i+1);
end loop;
else --小于128表示负数
for i in 1 .. vlength - 2 loop
result := result +
(Bytes(i) - 101) * power(100, (62 - Bytes(0)) - i+1);
end loop;
end if;
return(Result);
end unDumpNumber;
SQL> select unDumpNumber(dump(314.21)) from dual;
UNDUMPNUMBER(DUMP(314.21))
--------------------------
314.21