注册 登录
编程论坛 SQL Server论坛

贡献一段汉字转拼音码的函数

wsn 发布于 2006-03-07 11:05, 5081 次点击

--取出汉字的拼音首码
--入参:汉字字符串
--出参:汉字字符串首拼音码
CREATE function Fun_GetPY
(
@str nvarchar(4000)
)
returns nvarchar(4000)
as
begin

declare @word nchar(1),@PY nvarchar(4000)

set @PY=''

while len(@str)>0
begin
set @word=left(@str,1)

--如果非汉字字符,返回原字符
set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
then (
select top 1 PY
from
(
select 'A' as PY,N'驁' as word
union all select 'B',N'簿'
union all select 'C',N'錯'
union all select 'D',N'鵽'
union all select 'E',N'樲'
union all select 'F',N'鰒'
union all select 'G',N'腂'
union all select 'H',N'夻'
union all select 'J',N'攈'
union all select 'K',N'穒'
union all select 'L',N'鱳'
union all select 'M',N'旀'
union all select 'N',N'桛'
union all select 'O',N'漚'
union all select 'P',N'曝'
union all select 'Q',N'囕'
union all select 'R',N'鶸'
union all select 'S',N'蜶'
union all select 'T',N'籜'
union all select 'W',N'鶩'
union all select 'X',N'鑂'
union all select 'Y',N'韻'
union all select 'Z',N'咗'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC
)
else @word
end)
set @str=right(@str,len(@str)-1)
end

return @PY

end

12 回复
#2
wsn2006-03-07 11:20
顶啊
#3
wsn2006-03-07 16:39
没有人要用这个东西吗,做系统时要用的
#4
LouisXIV2006-03-07 17:18
不错,偶给加个精(这个论坛的处女精)
#5
wsn2006-03-08 11:05
谢主隆恩

#6
zhaofeng7012006-03-08 16:51

谢谢!

#7
zhou2008-03-30 11:50
提示: 作者被禁止或删除 内容自动屏蔽,只有管理员可见
#8
Saber02272008-04-01 12:54
函数不会用
LZ能给个用这个函数的例题吗?
先谢谢了。
#9
shezhenhui19892008-04-01 12:55
谢谢楼主啊
#10
jxyga1112008-05-13 18:43
還行
#11
happynight2008-05-14 08:44
好东西 收藏了 谢谢
1