SQL中有多种的函数,下面为您介绍sql中汉字转换为拼音的函数,供您参考。数据库中先自定义一个函数,再把下面代码写进去,功能是得到汉字拼音首字母:
如下:
SQL中有多种的函数,下面为您介绍sql中汉字转换为拼音的函数,供您参考。数据库中先自定义一个函数,再把下面代码写进去,功能是得到汉字拼音首字母: 如下: view source print? 01 create function fun_getPY(@str nvarchar(4000)) 02 returns nvarchar(4000) 03 as 04 begin 05 declare @word nchar(1),@PY nvarchar(4000) 06 set @PY='' 07 while len(@str)>0 08 begin 09 set @word=left(@str,1) 10 --如果非汉字字符,返回原字符 11 set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901 12 then (select top 1 PY from ( 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