Oracle 函数取汉字的拼音首字母

create or replace function f_ywm(chinese1 in varchar2)
return varchar2
/*
说明:此函数用于获取汉字的拼音声母,本函数只生成前10位汉字音序码。
用法:将要处理的字符作为参数传给此函数。

示例:
SQL> select f_ywm('我爱中华') from dual ;
输出:WAZH
*/
is
ls_one_hz varchar2(10);
ls_temp_py varchar2(100);
li_length integer;
i integer;
j integer;
li_count integer;
ls_py varchar2(100);
begin
    li_length := length(rtrim(ltrim(chinese1)));
    if nvl(li_length,0)=0 then
       li_length:=0;
    end if;
    ls_py := '';
    ls_one_hz := '';
    ls_temp_py := '';
    i := 1;
    LOOP
 if i > li_length then
  exit;
 end if;
        if length(ls_py) > 10 then
  exit;
 end if;
 ls_one_hz := substr(chinese1,i,1);
 if ascii(ls_one_hz) > 128 then
  ls_one_hz := substr(chinese1,i,1);
  --i := i + 1;

  select count(*) into li_count from t_ywm_zk where z = ls_one_hz;
  if li_count > 0 then
    select n into ls_temp_py from t_ywm_zk where z = ls_one_hz;
     if sqlcode < 0 then
                return('错误');
             end if;
   if ls_temp_py is null then
       ls_temp_py := '?';
    end if;
  else
     ls_temp_py := '?';
  end if;
  ls_temp_py := upper(ls_temp_py);
  ls_py := ls_py||ls_temp_py;
 elsif ascii(ls_one_hz) <> 32 then
  ls_one_hz := upper(ls_one_hz);
  ls_py := ls_py||ls_one_hz;
 end if;
 i := i + 1;
   END LOOP;
   return ls_py;
end;

转载于:https://www.cnblogs.com/BetterWF/archive/2012/07/14/2591617.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值