SQLServer取汉字拼音的函数展示

此文章主要介绍的是SQL Server取汉字拼音的函数,如果你对SQL Server取汉字拼音的函数心存好奇的话,以下的文章将会揭开它的神秘面纱,以下就是文章的详细内容介绍,望大家借鉴。

 
 
 
  1. Create function fun_getPY 
  2. @str nvarchar(4000) 
  3. returns nvarchar(4000) 
  4. as 
  5. begin 
  6. declare @word nchar(1),@PY nvarchar(4000) 
  7. set @PY='' 
  8. while len(@str)>0 
  9. begin 
  10. set @word=left(@str,1) 

如果非汉字字符,返回原字符

 
 
 
  1. set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901 
  2. then ( 
  3. select top 1 PY 
  4. from 
  5. select 'A' as PY,N'驁' as word 
  6. union all select 'B',N'簿' 
  7. union all select 'C',N'錯' 
  8. union all select 'D',N'鵽' 
  9. union all select 'E',N'樲' 
  10. union all select 'F',N'鰒' 
  11. union all select 'G',N'腂' 
  12. union all select 'H',N'夻' 
  13. union all select 'J',N'攈' 
  14. union all select 'K',N'穒' 
  15. union all select 'L',N'鱳' 
  16. union all select 'M',N'旀' 
  17. union all select 'N',N'桛' 
  18. union all select 'O',N'漚' 
  19. union all select 'P',N'曝' 
  20. union all select 'Q',N'囕' 
  21. union all select 'R',N'鶸' 
  22. union all select 'S',N'蜶' 
  23. union all select 'T',N'籜' 
  24. union all select 'W',N'鶩' 
  25. union all select 'X',N'鑂' 
  26. union all select 'Y',N'韻' 
  27. union all select 'Z',N'咗' 
  28. ) T 
  29. where word>=@word collate Chinese_PRC_CS_AS_KS_WS 
  30. order by PY ASC 
  31. else @word 
  32. end) 
  33. set @str=right(@str,len(@str)-1) 
  34. end 
  35. return @PY 
  36. end

以上的相关内容就是对SQL Server取汉字拼音的函数的介绍,望你能有所收获。


当前题目:SQLServer取汉字拼音的函数展示
本文来源:http://www.gydahua.com/article/dpohsic.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流