Knowledge Base Nr: 00156 plsqlhexdec.txt - http://www.swe-kaiser.de

Downloads:

PL/SQL: Dezimal nach Hexadezimal Wandlung

  
v_hexstring varchar2(12);
v_hexstring = decimal_to_hex(nvl(number,-1));

function decimal_to_hex (i_decimal in integer)
return varchar2 is
v_result varchar2(12);
v_hex_digit varchar2(1);
v_quotient integer;
v_remainder integer;
begin
if (i_decimal = null) then
v_result := null;
elsif (i_decimal < 10) then
v_result := to_char(i_decimal);
elsif (i_decimal < 16) then
v_result := chr(65+(i_decimal-10)); -- or 55 + idec
else
v_remainder := mod(i_decimal,16);
v_quotient := round((i_decimal - v_remainder) /16);
v_result := decimal_to_hex(v_quotient) || decimal_to_hex(v_remainder);
end if;

return v_result;
end decimal_to_hex;