SQL中有多種的函數(shù),下面為您介紹sql中漢字轉(zhuǎn)換為拼音的函數(shù),供您參考。數(shù)據(jù)庫中先自定義一個函數(shù),再把下面代碼寫進(jìn)去,功能是得到漢字拼音首字母:

創(chuàng)新互聯(lián)成立與2013年,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個夢想脫穎而出為使命,1280元昌吉做網(wǎng)站,已為上家服務(wù),為昌吉各地企業(yè)和個人服務(wù),聯(lián)系電話:028-86922220
如下:
view source print ?
01 | create function fun_getPY(@str nvarchar(4000)) |
05 | declare @wordnchar(1),@PY nvarchar(4000) |
11 | set @PY=@PY+(case when unicode(@word)between 19968and 19968+20901 |
12 | then (select top 1 PYfrom ( |
13 | select 'A' as PY,N'驁' as word |
14 | union all select 'B',N'簿' |
15 | union all select 'C',N'錯' |
16 | union all select 'D',N'鵽' |
17 | union all select 'E',N'樲' |
18 | union all select 'F',N'鰒' |
19 | union all select 'G',N'腂' |
20 | union all select 'H',N'夻' |
21 | union all select 'J',N'攈' |
22 | union all select 'K',N'穒' |
23 | union all select 'L',N'鱳' |
24 | union all select 'M',N'旀' |
25 | union all select 'N',N'桛' |
26 | union all select 'O',N'漚' |
27 | union all select 'P',N'曝' |
28 | union all select 'Q',N'囕' |
29 | union all select 'R',N'鶸' |
30 | union all select 'S',N'蜶' |
31 | union all select 'T',N'籜' |
32 | union all select 'W',N'鶩' |
33 | union all select 'X',N'鑂' |
34 | union all select 'Y',N'韻' |
35 | union all select 'Z',N'咗' |
37 | where word>=@wordcollate Chinese_PRC_CS_AS_KS_WS |
38 | order by PYASC)else @wordend) |
39 | set @str=right(@str,len(@str)-1) |
--函數(shù)調(diào)用實(shí)例:
select dbo.fun_getPY('中華人民共和國')
結(jié)果都為:ZHRMGHG
【編輯推薦】
SQL中的ISNULL函數(shù)介紹
Sql語言中的日期格式化函數(shù)getDate()
詳解SQL中的SUBSTRING函數(shù)
SQL中的CHARINDEX函數(shù)
SQL中自定義函數(shù)的存儲過程的區(qū)別
當(dāng)前標(biāo)題:SQL漢字轉(zhuǎn)換為拼音的函數(shù)
地址分享:
http://fisionsoft.com.cn/article/dphchig.html