|
Versions Of This Snippet::
Download a raw-text version of this code by clicking on "Download Version"
Latest Snippet Version: :1
FUNCTION DEC_TO( p_decimal number,
p_base pls_integer,
p_tamanho pls_integer default 2 ) return varchar2 is -- conversao de bases: decimal para qualquer base
sRetorno varchar2(50);
sRESTO varchar2(50);
nQUOC number;
nRESTO pls_integer;
nTam pls_integer;
--
begin
nQUOC := p_decimal;
sRESTO := '';
if nQUOC = 0 then
sRetorno := '0';
goto fim;
end if;
while nQUOC > 0 loop
if nQUOC > 1 then
nRESTO := MOD( nQUOC, p_base );
nQUOC := TRUNC( nQUOC/p_base );
else
nRESTO := 1;
nQUOC := 0;
end if;
if nResto < 10 then
sRESTO := sRESTO || to_char(nRESTO);
else
sRESTO := sRESTO || chr(65+nResto-10);
end if;
end loop;
sRetorno := '';
nTam := LENGTH( sRESTO );
for i in 0..nTam-1 loop
sRetorno := sRetorno || substr( sRESTO, nTam-i, 1 );
end loop;
<<fim>>
return ( LPAD( sRetorno, p_tamanho, '0' ) );
end dec_to;
Submit a new versionYou can submit a new version of this snippet if you have modified it and you feel it is appropriate to share with others..
|
||||||||||||||||||||||||||
