oracle 給的轉換函式實現 十六進位制---->十進位制

jidongzheng發表於2009-11-16

Create or replace FUNCTION hextodec (hexnum in char) RETURN number IS
x number;
digits number;
result number := 0;

current_digit char(1);
current_digit_dec number;
BEGIN
digits := length(hexnum);
for x in 1..digits loop
current_digit := upper(SUBSTR(hexnum, x, 1));
if current_digit in ('A','B','C','D','E','F') then
current_digit_dec := ascii(current_digit) - ascii('A') + 10;
else
current_digit_dec := to_number(current_digit);
end if;
result := (result * 16) + current_digit_dec;
end loop;
return result;
END;

-----------------------------------------------------------

以上只是給了個示例.

實際上有現成的.

select hextodec('BABA11') from dual;
select to_number('BABA11','XXXXXX') from dual;

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/197458/viewspace-1028751/,如需轉載,請註明出處,否則將追究法律責任。

相關文章