Oracle->convert to 34进制

本文介绍了一个PL/SQL函数,该函数能够将十进制整数转换为34进制字符串形式。通过循环和余数操作,函数实现了从十进制到34进制的转换,并使用特定字符集(A-Z对应10-33)来表示大于9的数值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值