Sqlserver将人名转换为拼音函数

Sqlserver 将人名转换为拼音函数
调用方法:

select [dbo].[procGetPinYin]('姓名') as Name

函数代码:

create function [dbo].[procGetPinYin](@str varchar(100))
returns varchar(8000)
as
begin
 declare @re varchar(8000),@crs varchar(10)
 declare @strlen int 
 select @strlen=len(@str),@re=''
 while @strlen>0
 begin  
  set @crs= substring(@str,@strlen,1)
      select @re=
        case
        when @crs<'吖' then @crs
        when @crs<='厑' then 'A'
        when @crs<='靉' then 'Ai'
        when @crs<='黯' then 'An'
        when @crs<='醠' then 'Ang'
        when @crs<='驁' then 'Ao'
        when @crs<='欛' then 'Ba'
        when @crs<='瓸' then 'Bai'
        when @crs<='瓣' then 'Ban'
        when @crs<='鎊' then 'Bang'
        when @crs<='鑤' then 'Bao'
        when @crs<='鐾' then 'Bei'
        when @crs<='輽' then 'Ben'
        when @crs<='鏰' then 'Beng'
        when @crs<='鼊' then 'Bi'
        when @crs<='變' then 'Bian'
        when @crs<='鰾' then 'Biao'
        when @crs<='彆' then 'Bie'
        when @crs<='鬢' then 'Bin'
        when @crs<='靐' then 'Bing'
        when @crs<='蔔' then 'Bo'
        when @crs<='簿' then 'Bu'
        when @crs<='囃' then 'Ca'
        when @crs<='乲' then 'Cai'
        when @crs<='爘' then 'Can'
        when @crs<='賶' then 'Cang'
        when @crs<='鼜' then 'Cao'
        when @crs<='簎' then 'Ce'
        when @crs<='笒' then 'Cen'
        when @crs<='乽' then 'Ceng'
        when @crs<='詫' then 'Cha'
        when @crs<='囆' then 'Chai'
        when @crs<='顫' then 'Chan'
        when @crs<='韔' then 'Chang'
        when @crs<='觘' then 'Chao'
        when @crs<='爡' then 'Che'
        when @crs<='讖' then 'Chen'
        when @crs<='秤' then 'Cheng'
        when @crs<='鷘' then 'Chi'
        when @crs<='銃' then 'Chong'
        when @crs<='殠' then 'Chou'
        when @crs<='矗' then 'Chu'
        when @crs<='踹' then 'Chuai'
        when @crs<='鶨' then 'Chuan'
        when @crs<='愴' then 'Chuang'
        when @crs<='顀' then 'Chui'
        when @crs<='蠢' then 'Chun'
        when @crs<='縒' then 'Chuo'
        when @crs<='嗭' then 'Ci'
        when @crs<='謥' then 'Cong'
        when @crs<='輳' then 'Cou'
        when @crs<='顣' then 'Cu'
        when @crs<='爨' then 'Cuan'
        when @crs<='臎' then 'Cui'
        when @crs<='籿' then 'Cun'
        when @crs<='錯' then 'Cuo'
        when @crs<='橽' then 'Da'
        when @crs<='靆' then 'Dai'
        when @crs<='饏' then 'Dan'
        when @crs<='闣' then 'Dang'
        when @crs<='纛' then 'Dao'
        when @crs<='的' then 'De'
        when @crs<='扽' then 'Den'
        when @crs<='鐙' then 'Deng'
        when @crs<='螮' then 'Di'
        when @crs<='嗲' then 'Dia'
        when @crs<='驔' then 'Dian'
        when @crs<='鑃' then 'Diao'
        when @crs<='嚸' then 'Die'
        when @crs<='顁' then 'Ding'
        when @crs<='銩' then 'Diu'
        when @crs<='霘' then 'Dong'
        when @crs<='鬭' then 'Dou'
        when @crs<='蠹' then 'Du'
        when @crs<='叾' then 'Duan'
        when @crs<='譵' then 'Dui'
        when @crs<='踲' then 'Dun'
        when @crs<='鵽' then 'Duo'
        when @crs<='鱷' then 'E'
        when @crs<='摁' then 'En'
        when @crs<='鞥' then 'Eng'
        when @crs<='樲' then 'Er'
        when @crs<='髮' then 'Fa'
        when @crs<='瀪' then 'Fan'
        when @crs<='放' then 'Fang'
        when @crs<='靅' then 'Fei'
        when @crs<='鱝' then 'Fen'
        when @crs<='覅' then 'Feng'
        when @crs<='梻' then 'Fo'
        when @crs<='鴀' then 'Fou'
        when @crs<='猤' then 'Fu'
        when @crs<='魀' then 'Ga'
        when @crs<='瓂' then 'Gai'
        when @crs<='灨' then 'Gan'
        when @crs<='戇' then 'Gang'
        when @crs<='鋯' then 'Gao'
        when @crs<='獦' then 'Ge'
        when @crs<='給' then 'Gei'
        when @crs<='搄' then 'Gen'
        when @crs<='堩' then 'Geng'
        when @crs<='兣' then 'Gong'
        when @crs<='購' then 'Gou'
        when @crs<='顧' then 'Gu'
        when @crs<='詿' then 'Gua'
        when @crs<='恠' then 'Guai'
        when @crs<='鱹' then 'Guan'
        when @crs<='撗' then 'Guang'
        when @crs<='鱥' then 'Gui'
        when @crs<='謴' then 'Gun'
        when @crs<='腂' then 'Guo'
        when @crs<='哈' then 'Ha'
        when @crs<='饚' then 'Hai'
        when @crs<='鶾' then 'Han'
        when @crs<='沆' then 'Hang'
        when @crs<='兞' then 'Hao'
        when @crs<='靏' then 'He'
        when @crs<='嬒' then 'Hei'
        when @crs<='恨' then 'Hen'
        when @crs<='堼' then 'Heng'
        when @crs<='鬨' then 'Hong'
        when @crs<='鱟' then 'Hou'
        when @crs<='鸌' then 'Hu'
        when @crs<='蘳' then 'Hua'
        when @crs<='蘾' then 'Huai'
        when @crs<='鰀' then 'Huan'
        when @crs<='鎤' then 'Huang'
        when @crs<='顪' then 'Hui'
        when @crs<='諢' then 'Hun'
        when @crs<='夻' then 'Huo'
        when @crs<='驥' then 'Ji'
        when @crs<='嗧' then 'Jia'
        when @crs<='鑳' then 'Jian'
        when @crs<='謽' then 'Jiang'
        when @crs<='釂' then 'Jiao'
        when @crs<='繲' then 'Jie'
        when @crs<='齽' then 'Jin'
        when @crs<='竸' then 'Jing'
        when @crs<='蘔' then 'Jiong'
        when @crs<='欍' then 'Jiu'
        when @crs<='爠' then 'Ju'
        when @crs<='羂' then 'Juan'
        when @crs<='钁' then 'Jue'
        when @crs<='攈' then 'Jun'
        when @crs<='鉲' then 'Ka'
        when @crs<='乫' then 'Kai'
        when @crs<='矙' then 'Kan'
        when @crs<='閌' then 'Kang'
        when @crs<='鯌' then 'Kao'
        when @crs<='騍' then 'Ke'
        when @crs<='褃' then 'Ken'
        when @crs<='鏗' then 'Keng'
        when @crs<='廤' then 'Kong'
        when @crs<='鷇' then 'Kou'
        when @crs<='嚳' then 'Ku'
        when @crs<='骻' then 'Kua'
        when @crs<='鱠' then 'Kuai'
        when @crs<='窾' then 'Kuan'
        when @crs<='鑛' then 'Kuang'
        when @crs<='鑎' then 'Kui'
        when @crs<='睏' then 'Kun'
        when @crs<='穒' then 'Kuo'
        when @crs<='鞡' then 'La'
        when @crs<='籟' then 'Lai'
        when @crs<='糷' then 'Lan'
        when @crs<='唥' then 'Lang'
        when @crs<='軂' then 'Lao'
        when @crs<='餎' then 'Le'
        when @crs<='脷' then 'Lei'
        when @crs<='睖' then 'Leng'
        when @crs<='瓈' then 'Li'
        when @crs<='倆' then 'Lia'
        when @crs<='纞' then 'Lian'
        when @crs<='鍄' then 'Liang'
        when @crs<='瞭' then 'Liao'
        when @crs<='鱲' then 'Lie'
        when @crs<='轥' then 'Lin'
        when @crs<='炩' then 'Ling'
        when @crs<='咯' then 'Liu'
        when @crs<='贚' then 'Long'
        when @crs<='鏤' then 'Lou'
        when @crs<='氇' then 'Lu'
        when @crs<='鑢' then 'Lv'
        when @crs<='亂' then 'Luan'
        when @crs<='擽' then 'Lue'
        when @crs<='論' then 'Lun'
        when @crs<='鱳' then 'Luo'
        when @crs<='嘛' then 'Ma'
        when @crs<='霢' then 'Mai'
        when @crs<='蘰' then 'Man'
        when @crs<='蠎' then 'Mang'
        when @crs<='唜' then 'Mao'
        when @crs<='癦' then 'Me'
        when @crs<='嚜' then 'Mei'
        when @crs<='們' then 'Men'
        when @crs<='霥' then 'Meng'
        when @crs<='羃' then 'Mi'
        when @crs<='麵' then 'Mian'
        when @crs<='廟' then 'Miao'
        when @crs<='鱴' then 'Mie'
        when @crs<='鰵' then 'Min'
        when @crs<='詺' then 'Ming'
        when @crs<='謬' then 'Miu'
        when @crs<='耱' then 'Mo'
        when @crs<='麰' then 'Mou'
        when @crs<='旀' then 'Mu'
        when @crs<='魶' then 'Na'
        when @crs<='錼' then 'Nai'
        when @crs<='婻' then 'Nan'
        when @crs<='齉' then 'Nang'
        when @crs<='臑' then 'Nao'
        when @crs<='呢' then 'Ne'
        when @crs<='焾' then 'Nei'
        when @crs<='嫩' then 'Nen'
        when @crs<='能' then 'Neng'
        when @crs<='嬺' then 'Ni'
        when @crs<='艌' then 'Nian'
        when @crs<='釀' then 'Niang'
        when @crs<='脲' then 'Niao'
        when @crs<='钀' then 'Nie'
        when @crs<='拰' then 'Nin'
        when @crs<='濘' then 'Ning'
        when @crs<='靵' then 'Niu'
        when @crs<='齈' then 'Nong'
        when @crs<='譳' then 'Nou'
        when @crs<='搙' then 'Nu'
        when @crs<='衄' then 'Nv'
        when @crs<='瘧' then 'Nue'
        when @crs<='燶' then 'Nuan'
        when @crs<='桛' then 'Nuo'
        when @crs<='鞰' then 'O'
        when @crs<='漚' then 'Ou'
        when @crs<='袙' then 'Pa'
        when @crs<='磗' then 'Pai'
        when @crs<='鑻' then 'Pan'
        when @crs<='胖' then 'Pang'
        when @crs<='礮' then 'Pao'
        when @crs<='轡' then 'Pei'
        when @crs<='喯' then 'Pen'
        when @crs<='喸' then 'Peng'
        when @crs<='鸊' then 'Pi'
        when @crs<='騙' then 'Pian'
        when @crs<='慓' then 'Piao'
        when @crs<='嫳' then 'Pie'
        when @crs<='聘' then 'Pin'
        when @crs<='蘋' then 'Ping'
        when @crs<='魄' then 'Po'
        when @crs<='哛' then 'Pou'
        when @crs<='曝' then 'Pu'
        when @crs<='蟿' then 'Qi'
        when @crs<='髂' then 'Qia'
        when @crs<='縴' then 'Qian'
        when @crs<='瓩' then 'Qiang'
        when @crs<='躈' then 'Qiao'
        when @crs<='籡' then 'Qie'
        when @crs<='藽' then 'Qin'
        when @crs<='櫦' then 'Qing'
        when @crs<='瓗' then 'Qiong'
        when @crs<='糗' then 'Qiu'
        when @crs<='覻' then 'Qu'
        when @crs<='勸' then 'Quan'
        when @crs<='礭' then 'Que'
        when @crs<='囕' then 'Qun'
        when @crs<='橪' then 'Ran'
        when @crs<='讓' then 'Rang'
        when @crs<='繞' then 'Rao'
        when @crs<='熱' then 'Re'
        when @crs<='餁' then 'Ren'
        when @crs<='陾' then 'Reng'
        when @crs<='馹' then 'Ri'
        when @crs<='穃' then 'Rong'
        when @crs<='嶿' then 'Rou'
        when @crs<='擩' then 'Ru'
        when @crs<='礝' then 'Ruan'
        when @crs<='壡' then 'Rui'
        when @crs<='橍' then 'Run'
        when @crs<='鶸' then 'Ruo'
        when @crs<='栍' then 'Sa'
        when @crs<='虄' then 'Sai'
        when @crs<='閐' then 'San'
        when @crs<='喪' then 'Sang'
        when @crs<='髞' then 'Sao'
        when @crs<='飋' then 'Se'
        when @crs<='篸' then 'Sen'
        when @crs<='縇' then 'Seng'
        when @crs<='霎' then 'Sha'
        when @crs<='曬' then 'Shai'
        when @crs<='鱔' then 'Shan'
        when @crs<='緔' then 'Shang'
        when @crs<='潲' then 'Shao'
        when @crs<='欇' then 'She'
        when @crs<='瘮' then 'Shen'
        when @crs<='賸' then 'Sheng'
        when @crs<='瓧' then 'Shi'
        when @crs<='鏉' then 'Shou'
        when @crs<='虪' then 'Shu'
        when @crs<='誜' then 'Shua'
        when @crs<='卛' then 'Shuai'
        when @crs<='腨' then 'Shuan'
        when @crs<='灀' then 'Shuang'
        when @crs<='睡' then 'Shui'
        when @crs<='鬊' then 'Shun'
        when @crs<='鑠' then 'Shuo'
        when @crs<='乺' then 'Si'
        when @crs<='鎹' then 'Song'
        when @crs<='瘶' then 'Sou'
        when @crs<='鷫' then 'Su'
        when @crs<='算' then 'Suan'
        when @crs<='鐩' then 'Sui'
        when @crs<='潠' then 'Sun'
        when @crs<='蜶' then 'Suo'
        when @crs<='襨' then 'Ta'
        when @crs<='燤' then 'Tai'
        when @crs<='賧' then 'Tan'
        when @crs<='燙' then 'Tang'
        when @crs<='畓' then 'Tao'
        when @crs<='蟘' then 'Te'
        when @crs<='朰' then 'Teng'
        when @crs<='趯' then 'Ti'
        when @crs<='舚' then 'Tian'
        when @crs<='糶' then 'Tiao'
        when @crs<='餮' then 'Tie'
        when @crs<='乭' then 'Ting'
        when @crs<='憅' then 'Tong'
        when @crs<='透' then 'Tou'
        when @crs<='鵵' then 'Tu'
        when @crs<='褖' then 'Tuan'
        when @crs<='駾' then 'Tui'
        when @crs<='坉' then 'Tun'
        when @crs<='籜' then 'Tuo'
        when @crs<='韤' then 'Wa'
        when @crs<='顡' then 'Wai'
        when @crs<='贎' then 'Wan'
        when @crs<='朢' then 'Wang'
        when @crs<='躛' then 'Wei'
        when @crs<='璺' then 'Wen'
        when @crs<='齆' then 'Weng'
        when @crs<='齷' then 'Wo'
        when @crs<='鶩' then 'Wu'
        when @crs<='衋' then 'Xi'
        when @crs<='鏬' then 'Xia'
        when @crs<='鼸' then 'Xian'
        when @crs<='鱌' then 'Xiang'
        when @crs<='斆' then 'Xiao'
        when @crs<='躞' then 'Xie'
        when @crs<='釁' then 'Xin'
        when @crs<='臖' then 'Xing'
        when @crs<='敻' then 'Xiong'
        when @crs<='齅' then 'Xiu'
        when @crs<='蓿' then 'Xu'
        when @crs<='贙' then 'Xuan'
        when @crs<='瀥' then 'Xue'
        when @crs<='鑂' then 'Xun'
        when @crs<='齾' then 'Ya'
        when @crs<='灩' then 'Yan'
        when @crs<='樣' then 'Yang'
        when @crs<='鑰' then 'Yao'
        when @crs<='岃' then 'Ye'
        when @crs<='齸' then 'Yi'
        when @crs<='檼' then 'Yin'
        when @crs<='譍' then 'Ying'
        when @crs<='喲' then 'Yo'
        when @crs<='醟' then 'Yong'
        when @crs<='鼬' then 'You'
        when @crs<='爩' then 'Yu'
        when @crs<='願' then 'Yuan'
        when @crs<='鸙' then 'Yue'
        when @crs<='韻' then 'Yun'
        when @crs<='雥' then 'Za'
        when @crs<='縡' then 'Zai'
        when @crs<='饡' then 'Zan'
        when @crs<='臟' then 'Zang'
        when @crs<='竈' then 'Zao'
        when @crs<='稄' then 'Ze'
        when @crs<='鱡' then 'Zei'
        when @crs<='囎' then 'Zen'
        when @crs<='贈' then 'Zeng'
        when @crs<='醡' then 'Zha'
        when @crs<='瘵' then 'Zhai'
        when @crs<='驏' then 'Zhan'
        when @crs<='瞕' then 'Zhang'
        when @crs<='羄' then 'Zhao'
        when @crs<='鷓' then 'Zhe'
        when @crs<='黮' then 'Zhen'
        when @crs<='證' then 'Zheng'
        when @crs<='豒' then 'Zhi'
        when @crs<='諥' then 'Zhong'
        when @crs<='驟' then 'Zhou'
        when @crs<='鑄' then 'Zhu'
        when @crs<='爪' then 'Zhua'
        when @crs<='跩' then 'Zhuai'
        when @crs<='籑' then 'Zhuan'
        when @crs<='戅' then 'Zhuang'
        when @crs<='鑆' then 'Zhui'
        when @crs<='稕' then 'Zhun'
        when @crs<='籱' then 'Zhuo'
        when @crs<='漬' then 'Zi'
        when @crs<='縱' then 'Zong'
        when @crs<='媰' then 'Zou'
        when @crs<='謯' then 'Zu'
        when @crs<='攥' then 'Zuan'
        when @crs<='欈' then 'Zui'
        when @crs<='銌' then 'Zun'
        when @crs<='咗' then 'Zuo'
        else  @crs end+''+@re,@strlen=@strlen-1 
   end
 return(@re)
end

GO


原理:汉字是按照拼音有序排列的,比如zhong这个拼音对应的中、终、种。。。在这个有序区间内,找到其最大值对应的汉字’諥’,以及他上一个拼音zhi的最大值’豒’,落在’豒’和’諥’之间的,其拼音为zhong。其余的同理,就可以得到每个汉字对应的拼音了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值