首页 > 数据库

MSSQL汉字转拼音函数

时间:2009-06-01 18:28:27  作者:OSnow  我要投稿
Linux初探欢迎您的投稿,投放方法请点击这里查看,我们会定期赠送精美小礼品给优秀的投稿作者。海纳百川 取则行远!LinuxGoo欢迎您的到来。
/* -------------------------------------------------------------函数: fn_GetPinyin描述: 汉字转拼音(无数据表版)使用: dbo.fn_GetPinyin('中华人民共和国'......

/* -------------------------------------------------------------
函数: fn_GetPinyin
描述: 汉字转拼音(无数据表版)
使用: dbo.fn_GetPinyin('中华人民共和国') = zhonghuarenmingongheguo
作者: 流香羽
博客: http://hi.baidu.com/流香羽
------------------------------------------------------------- */

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[fn_GetPinyin]') AND xtype in (N'FN', N'IF', N'TF'))
BEGIN
execute dbo.sp_executesql @statement = N'create function [dbo].[fn_GetPinyin](@words nvarchar(2000))
returns varchar(8000)
as
begin
declare @word nchar(1)
declare @pinyin varchar(8000)
declare @i int
declare @words_len int
declare @unicode int
set @pinyin = ''''
set @i = 1
set @words = ltrim(rtrim(@words))
set @words_len = len(@words)
while (@i <= @words_len) --循环取字符
begin
set @word = substring(@words, @i, 1)
set @unicode = unicode(@word)
set @pinyin = @pinyin (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 ''ai'',N''靉''
union all select ''an'',N''黯''
union all select ''ang'',N''醠''
union all select ''ao'',N''驁''
union all select ''ba'',N''欛''
union all select ''bai'',N''瓸'' --韛兡瓸
union all select ''ban'',N''瓣''
union all select ''bang'',N''鎊''
union all select ''bao'',N''鑤''
union all select ''bei'',N''鐾''
union all select ''ben'',N''輽''
union all select ''beng'',N''鏰''
union all select ''bi'',N''鼊''
union all select ''bian'',N''變''
union all select ''biao'',N''鰾''
union all select ''bie'',N''彆''
union all select ''bin'',N''鬢''
union all select ''bing'',N''靐''
union all select ''bo'',N''蔔''
union all select ''bu'',N''簿''
union all select ''ca'',N''囃''
union all select ''cai'',N''乲'' --縩乲
union all select ''can'',N''爘''
union all select ''cang'',N''賶''
union all select ''cao'',N''鼜''
union all select ''ce'',N''簎''
union all select ''cen'',N''笒''
union all select ''ceng'',N''乽'' --硛硳岾猠乽

如果您需转载 MSSQL汉字转拼音函数,请注明来自LinuxGoo.com,其版权归原作者所有。请广大网友留言时遵纪守法,使用文明用语。如果您在应用中有什么问题,请在下面留言,我们会尽快解答。
来顶一下
近回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
相关文章
栏目热门