当前位置: 代码迷 >> SQL >> sql 依据汉字获取拼音
  详细解决方案

sql 依据汉字获取拼音

热度:11   发布时间:2016-05-05 13:15:47.0
sql 根据汉字获取拼音
create function f_GetPinYin(@str varchar(500))returns varchar(500)asbegin   declare @cyc int,@length int,@str1 varchar(100),@charcate varbinary(20)   set @cyc=1--从第几个字开始取   set @length=len(@str)--输入汉字的长度   set @str1=''--用于存放返回值   while @cyc<[email protected]       begin            select @charcate=cast(substring(@str,@cyc,1) as varbinary)--每次取出一个字并将其转变成二进制,便于与GBK编码表进行比较 if @charcate>=0XB0A1 and @charcate<=0XB0C4         set @[email protected]+'A'--说明此汉字的首字母为A,以下同上    else if @charcate>=0XB0C5 and @charcate<=0XB2C0      set @[email protected]+'B' else if @charcate>=0XB2C1 and @charcate<=0XB4ED      set @[email protected]+'C' else if @charcate>=0XB4EE and @charcate<=0XB6E9      set @[email protected]+'D' else if @charcate>=0XB6EA and @charcate<=0XB7A1                       set @[email protected]+'E' else if @charcate>=0XB7A2 and @charcate<=0XB8C0             set @[email protected]+'F' else if @charcate>=0XB8C1 and @charcate<=0XB9FD                       set @[email protected]+'G' else if @charcate>=0XB9FE and @charcate<=0XBBF6       set @[email protected]+'H' else if @charcate>=0XBBF7 and @charcate<=0XBFA5       set @[email protected]+'J' else if @charcate>=0XBFA6 and @charcate<=0XC0AB       set @[email protected]+'K' else if @charcate>=0XC0AC and @charcate<=0XC2E7       set @[email protected]+'L' else if @charcate>=0XC2E8 and @charcate<=0XC4C2       set @[email protected]+'M' else if @charcate>=0XC4C3 and @charcate<=0XC5B5       set @[email protected]+'N'   else if @charcate>=0XC5B6 and @charcate<=0XC5BD       set @[email protected]+'O' else if @charcate>=0XC5BE and @charcate<=0XC6D9       set @[email protected]+'P' else if @charcate>=0XC6DA and @charcate<=0XC8BA       set @[email protected]+'Q' else if @charcate>=0XC8BB and @charcate<=0XC8F5                   set @[email protected]+'R' else if @charcate>=0XC8F6 and @charcate<=0XCBF9       set @[email protected]+'S' else if @charcate>=0XCBFA and @charcate<=0XCDD9      set @[email protected]+'T' else if @charcate>=0XCDDA and @charcate<=0XCEF3        set @[email protected]+'W' else if @charcate>=0XCEF4 and @charcate<=0XD1B8        set @[email protected]+'X' else if @charcate>=0XD1B9 and @charcate<=0XD4D0       set @[email protected]+'Y' else if @charcate>=0XD4D1 and @charcate<=0XD7F9       set @[email protected]+'Z'       set @[email protected]+1--取出输入汉字的下一个字 end return @str1--返回输入汉字的首字母       end --测试数据--select dbo.f_GetPinYin('中华(人民)共和国')

  相关解决方案