SQL汉字转换为拼音的函数

SQL中有多种的函数,下面为您介绍sql中汉字转换为拼音的函数,供您参考。数据库中先自定义一个函数,再把下面代码写进去,功能是得到汉字拼音首字母:

创新互联成立与2013年,是专业互联网技术服务公司,拥有项目成都做网站、成都网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元昌吉做网站,已为上家服务,为昌吉各地企业和个人服务,联系电话:028-86922220

如下:

view source print ?

01create function fun_getPY(@str nvarchar(4000))
02returns nvarchar(4000)
03as
04begin
05declare @wordnchar(1),@PY nvarchar(4000)
06set @PY=''
07while len(@str)>0
08begin
09set @word=left(@str,1)
10--如果非汉字字符,返回原字符
11set @PY=@PY+(case when unicode(@word)between 19968and 19968+20901
12then (select top 1 PYfrom (
13select 'A' as PY,N'驁' as word
14union all select 'B',N'簿'
15union all select 'C',N'錯'
16union all select 'D',N'鵽'
17union all select 'E',N'樲'
18union all select 'F',N'鰒'
19union all select 'G',N'腂'
20union all select 'H',N'夻'
21union all select 'J',N'攈'
22union all select 'K',N'穒'
23union all select 'L',N'鱳'
24union all select 'M',N'旀'
25union all select 'N',N'桛'
26union all select 'O',N'漚'
27union all select 'P',N'曝'
28union all select 'Q',N'囕'
29union all select 'R',N'鶸'
30union all select 'S',N'蜶'
31union all select 'T',N'籜'
32union all select 'W',N'鶩'
33union all select 'X',N'鑂'
34union all select 'Y',N'韻'
35union all select 'Z',N'咗'
36) T 
37where word>=@wordcollate Chinese_PRC_CS_AS_KS_WS 
38order by PYASC)else @wordend)
39set @str=right(@str,len(@str)-1)
40end
41return @PY
42end

--函数调用实例:
select dbo.fun_getPY('中华人民共和国')
结果都为:ZHRMGHG

【编辑推荐】

SQL中的ISNULL函数介绍

Sql语言中的日期格式化函数getDate()

详解SQL中的SUBSTRING函数

SQL中的CHARINDEX函数

SQL中自定义函数的存储过程的区别

名称栏目:SQL汉字转换为拼音的函数
转载源于:http://www.csdahua.cn/qtweb/news41/256641.html

网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网