2008-03-31
Oracle->convert to 34进制
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;
- 浏览: 4244 次

- 详细资料
搜索本博客
最近加入圈子
最新评论
-
NET判断输入是否为double ...
受教了!谢谢楼主
-- by liuzhenyu170 -
一个截取字符串的方法
呵呵谢谢各位,我是想让他成为一个通用的东西,以后在编写存储过程时,可以直接用,就 ...
-- by 心似海 -
动态SQL
既然是存储过程,当temp_str的值有很多的时候, 可以考虑把temp_str ...
-- by armorking -
一个截取字符串的方法
用函数跑得会比较慢。。。不如再来个表像二楼说的1:N 想了想,写成下面这样貌视 ...
-- by qiuyuanshan -
一个截取字符串的方法
明明A、B两个字段是1:N关系, 用两张主从关系的表来描述,非常轻松 却偏偏要把 ...
-- by armorking






评论排行榜