oracle中文谐音,很有趣的,汉字转换为其发音的首字母

createorreplacefunctioncsound(c in varchar2,op in integerdefault1)

returnvarchar2/*

作者:chensq@itpub.net

日期:2005-05-18 22:30

说明:此函数用于将汉字转换为其发音的首字母,对于ascii码值在1~128间的字符不作任何处理,其它字符返回错误信息。

用法:默认情况下,只对第一个字符进行转换,如果加上不等于1的参数,则对全字符串进行处理,支持中英文合编。如:

SQL> select csound('中国人用自己的sound()函数',2) from dual ;

CSOUND('中国人用自己的SOUND()

-------------------------------------------------------------

ZGRYZJDsound()HS

SQL> select csound('中国人用自己的sound()函数') from dual ;

CSOUND('中国人用自己的SOUND()

--------------------------------------------------------------

Z

备注:此函数只在ZHS16GBK字符集的Oracle 9.2中通过,其它平台没有测试,请根据实际需要作相应的修改。

*/is

c1 varchar2(2);c2 varchar2(2);p integer;n1 integer;n2 integer;csound varchar2(32767);beginifop=1 then p:=1;

elsep:=length(c);endif;

fori in 1..p

loop

c2:=substr(c,i,1);n1:=floor(ascii(c2)/256);n2:=mod(ascii(c2),256);

ifn1=0andn2<=129 then

c1:=c2;elsif n2<>127andn2<>255andnot(n2 between 0and63)then

selectcasewhen c2>='丂'andc2='芭'andc2='擦'andc2='搭'andc2='蛾'andc2='发'andc2='噶'andc2='哈'andc2='击'andc2='喀'andc2='垃'andc2='妈'andc2='拿'andc2='哦'andc2='啪'andc2='期'andc2='然'andc2='撒'andc2='塌'andc2='挖'andc2='稀'andc2='压'andc2='匝'andc2<='鼱'then'Z'end

into c1

from dual;

elsec1:='er';endif;csound:=csound||c1;end loop;

returncsound;end;SQL>select csound('中国人用自己的sound()函数',2)from dual;CSOUND('中国人用自己的SOUND()

----------------------------------------------------------------

ZGRYZJDsound()HS

SQL> select csound('台海分离美国得利',2) from dual ;

CSOUND('台海分离美国得利',2)

---------------------------------------------------------------

THFLMGDL

SQL> select csound('热烈庆祝财富论坛圆满召开',2) from dual ;

CSOUND('热烈庆祝财富论坛圆满召---------------------------------------------------------------RLQZCFLTYMZK[@more@]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
--此函数默认返回汉字拼音的首字母,第二个参数不为空则返回全拼。 create or replace function f_getFirstOrFullSpell(p_cnStr In varchar2,p_sign In number default null) return varchar2 as lv_spell varchar2(200); lv_temp Varchar2(10); lv_char varchar2(10); --lv_bytes varchar2(100); li_bytes Integer; --li_pos Integer; begin if p_cnStr is null then return ''; end if; for i In 1..length(p_cnStr) loop lv_char:=substr(p_cnStr,i,1); if lengthb(lv_char) = 1 then lv_spell:=lv_spell||lv_char; elsif lengthb(lv_char) = 2 then --Select replace(substrb(dump(lv_char,1010),instrb(dump(lv_char,1010),'ZHS16GBK:')),'ZHS16GBK: ','') Into lv_bytes from dual; --li_pos:=instr(lv_bytes,','); --li_bytes:=substr(lv_bytes,1,li_pos-1)*256+substr(lv_bytes,li_pos+1)-256*256; Select ascii(lv_char)-256*256 Into li_bytes From dual; select max(spell) Into lv_temp from table(f_getSpellcode) where code<=li_bytes; if p_sign is null then lv_spell:=lv_spell||substr(lv_temp,1,1); else lv_spell:=lv_spell||lv_temp; end if; elsif lengthb(lv_char) = 3 then --Select replace(substrb(dump(convert(lv_char,'ZHS16GBK','UTF8'),1010),instrb(dump(convert(lv_char,'ZHS16GBK','UTF8'),1010),'UTF8:')),'UTF8: ','') --Into lv_bytes from dual; --li_pos:=instr(lv_bytes,','); --li_bytes:=substr(lv_bytes,1,li_pos-1)*256+substr(lv_bytes,li_pos+1)-256*256; Select ascii(lv_char)-256*256 Into li_bytes From dual; select max(spell) Into lv_temp from table(f_getSpellcode) where code<=li_bytes; if p_sign is null then lv_spell:=lv_spell||substr(lv_char,1,1); else lv_spell:=lv_spell||lv_char; end if; end if; end loop; return lv_spell; end; --hanjs,07-10-24,此函数默认返回汉字拼音的首字母,第二个参数不为空则返回全拼。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值