create or replace function convert_decimal_to_base34(p_decimal_num in integer)
return varchar2 is
v_Result_str varchar2(7);
v_replace_str varchar2(1);
v_baseIndex int := 6;
v_remainder int := 0;
v_quotient int := p_decimal_num;
begin
---------Initial string--------
v_Result_str := '0000000';
loop
v_remainder := mod(v_quotient, 34);
------------replace decimal_num with base 34 code
select decode(v_remainder,
'10',
'A',
'11',
'B',
'12',
'C',
'13',
'D',
'14',
'E',
'15',
'F',
'16',
'G',
'17',
'H',
'18',
'J',
'19',
'K',
'20',
'L',
'21',
'M',
'22',
'N',
'23',
'P',
'24',
'Q',
'25',
'R',
'26',
'S',
'27',
'T',
'28',
'U',
'29',
'V',
'30',
'W',
'31',
'X',
'32',
'Y',
'33',
'Z',
v_remainder)
into v_replace_str
from dual;
-------reform string-------
v_result_str := substr(v_result_str, 0, v_baseIndex) || v_replace_str ||
substr(v_result_str, v_baseIndex + 2, 6 - v_baseIndex);
--------------
v_quotient := floor(v_quotient / 34);
v_baseIndex := v_baseIndex - 1;
exit when v_baseIndex = 0;
----------Do while conditional loop ----------
end loop;
return(v_Result_str);
end convert_decimal_to_base34;
return varchar2 is
v_Result_str varchar2(7);
v_replace_str varchar2(1);
v_baseIndex int := 6;
v_remainder int := 0;
v_quotient int := p_decimal_num;
begin
---------Initial string--------
v_Result_str := '0000000';
loop
v_remainder := mod(v_quotient, 34);
------------replace decimal_num with base 34 code
select decode(v_remainder,
'10',
'A',
'11',
'B',
'12',
'C',
'13',
'D',
'14',
'E',
'15',
'F',
'16',
'G',
'17',
'H',
'18',
'J',
'19',
'K',
'20',
'L',
'21',
'M',
'22',
'N',
'23',
'P',
'24',
'Q',
'25',
'R',
'26',
'S',
'27',
'T',
'28',
'U',
'29',
'V',
'30',
'W',
'31',
'X',
'32',
'Y',
'33',
'Z',
v_remainder)
into v_replace_str
from dual;
-------reform string-------
v_result_str := substr(v_result_str, 0, v_baseIndex) || v_replace_str ||
substr(v_result_str, v_baseIndex + 2, 6 - v_baseIndex);
--------------
v_quotient := floor(v_quotient / 34);
v_baseIndex := v_baseIndex - 1;
exit when v_baseIndex = 0;
----------Do while conditional loop ----------
end loop;
return(v_Result_str);
end convert_decimal_to_base34;