oracle 62进制序列号

create or replace function GetSerial62(v_lpad number default 0)
return varchar2
IS
v_tmp number(38,0);
v_str char(62);
v_result varchar2(128);
BEGIN
v_str := '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
v_tmp := SEQ_Serial_62.nextval;
v_result := '';

if v_lpad > 128 then
   return v_result;
end if;

while v_tmp <> 0  loop
    v_result := v_result||substr(v_str,mod(v_tmp,62)+1,1);
    v_tmp := trunc(v_tmp / 62);
end loop;

select reverse(v_result) into v_result from dual;
if v_lpad > length(v_result) then
     v_result := lpad(v_result,v_lpad,'0');
end if;

--DBMS_OUTPUT.PUT_LINE('====['||v_result||']==');
return v_result;
end GetSerial62;





create or replace function GetSerial62(v_serial number,v_lpad number default 0)
return varchar2
IS
v_tmp number(38,0);
v_number_tmp number(10);
v_char_tmp char(1);
v_result varchar2(128);
BEGIN

v_tmp := v_serial;
v_result := '';

if v_lpad > 128 then
   return v_result;
end if;

while v_tmp <> 0  loop
    v_number_tmp := mod(v_tmp,62);
    
    select decode(v_number_tmp,0 ,'0',1 ,'1',2 ,'2',3 ,'3',4 ,'4',5 ,'5',
                                      6 ,'6',7 ,'7',8 ,'8',9 ,'9',10,'a',11,'b',
                                      12,'c',13,'d',14,'e',15,'f',16,'g',17,'h',
                                      18,'i',19,'j',20,'k',21,'l',22,'m',23,'n',
                                      24,'o',25,'p',26,'q',27,'r',28,'s',29,'t',
                                      30,'u',31,'v',32,'w',33,'x',34,'y',35,'z',
                                      36,'A',37,'B',38,'C',39,'D',40,'E',41,'F',
                                      42,'G',43,'H',44,'I',45,'J',46,'K',47,'L',
                                      48,'M',49,'N',50,'O',51,'P',52,'Q',53,'R',
                                      54,'S',55,'T',56,'U',57,'V',58,'W',59,'X',
                                      60,'Y',61,'Z','')  into v_char_tmp from dual;
    
    v_result := v_result||v_char_tmp;
    v_tmp := trunc(v_tmp / 62);
end loop;

select reverse(v_result) into v_result from dual;
if v_lpad > length(v_result) then 
     v_result := lpad(v_result,v_lpad,'0');
end if;

--DBMS_OUTPUT.PUT_LINE('====['||v_result||']==');
return v_result;
end GetSerial62;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值