鬼妈妈电影动漫:oracle汉字到拼音的转换

来源:百度文库 编辑:九乡新闻网 时间:2024/04/25 21:30:33

--注:此函数只在ZHS16GBK字符集的Oracle 9.2中通过,其它平台没有测试,请根据实际需要作相应的修改
create or replace function csound(c  in varchar2,
                                  op in integer default 1   --加上不等于1的参数,则对全字符串进行处理,支持中英文合编
                                 )
return varchar2
is
c1     varchar2(2);
c2     varchar2(2);
     integer;
n1     integer;
n2     integer;
csound varchar2(32767);
begin
    if op=1 then p:=1 ;
    else p:=length(c);
    end if;
    for i in 1..p
    loop
    c2:=substr(c,i,1);
    n1:=floor(ascii(c2)/256);
    n2:=mod(ascii(c2),256);
    if n1=0 and n2<=129 then
       c1:=c2;      
    elsif n2<>127 and n2<>255
          and not (n2 between 0 and 63)  then
       select
       case
       when c2>='丂' and c2<'芭'  then 'A'
      when c2>='芭' and c2<'擦'  then 'B'
       when c2>='擦' and c2<'搭'  then 'C'
       when c2>='搭' and c2<'蛾'  then 'D'
       when c2>='蛾' and c2<'发'  then 'E'
       when c2>='发' and c2<'噶'  then 'F'
       when c2>='噶' and c2<'哈'  then 'G'
       when c2>='哈' and c2<'击'  then 'H'
       when c2>='击' and c2<'喀'  then 'J'
       when c2>='喀' and c2<'垃'  then 'K'
       when c2>='垃' and c2<'妈'  then 'L'
       when c2>='妈' and c2<'拿'  then 'M'
       when c2>='拿' and c2<'哦'  then 'N'
       when c2>='哦' and c2<'啪'  then 'O'
       when c2>='啪' and c2<'期'  then 'P'
       when c2>='期' and c2<'然'  then 'Q'
       when c2>='然' and c2<'撒'  then 'R'
       when c2>='撒' and c2<'塌'  then 'S'
       when c2>='塌' and c2<'挖'  then 'T'
       when c2>='挖' and c2<'稀'  then 'W'
       when c2>='稀' and c2<'压'  then 'X'
       when c2>='压' and c2<'匝'  then 'Y'
       when c2>='匝' and c2<='鼱' then 'Z' end
       into c1
       from dual;
       else
       c1:='er';
       end if;
       csound:=csound||c1;
       end loop;
    return csound;
end;
select csound('我爱伟大的周星驰',2) from dual
select ascii('丂') from dual;