sql语句 汉字转拼音首字母
Posted zaibaobaoni
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql语句 汉字转拼音首字母相关的知识,希望对你有一定的参考价值。
create function GetPY(@str varchar(500))
returns varchar(500)
as
begin
declare @cyc int,@length int,@str1 varchar(100),@charcate varbinary(20)
set @cyc=1--从第几个字开始取
set @length=len(@str)--输入汉字的长度
set @str1=‘‘--用于存放返回值
while @cyc<=1
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
以上是关于sql语句 汉字转拼音首字母的主要内容,如果未能解决你的问题,请参考以下文章
C#汉字转拼音(npinyin)将中文转换成拼音全文或首字母