首页 > 资讯列表 > 编程/数据库 >> 数据库操作教程

sqlServer获取汉字字串的拼音声母

数据库操作教程 2022-09-23 16:54:31 转载来源: 网络整理/侵权必删

复制代码代码如下:CREATEfunctionfGetPy(@strvarchar(500)='')returnsvarchar(500)asbegindeclare@strlenint,@returnvarchar(500),@iiintdeclare@cnchar(1),@chnnchar(1)select@strlen=len(@str),@return='',@ii=0set@ii=0while@ii<@strlenbeginselect@ii=@ii+1,@chn=substring(@str,@ii,1)if@chn>='吖'select@c=char(count(*)+63)from(selecttop27*from(selectchn='吖'unionallselect'八'unionallselect'嚓'unionallselect'咑'unionallselect'妸'unionallselect'发'unionallselect'旮'unionallselect'铪'unionallselect'丌'--becausehaveno'i'unional

复制代码 代码如下:

CREATE function fGetPy(@str varchar(500)='')
returns varchar(500)
as
begin
declare @strlen int,@return varchar(500),@ii int
declare @c nchar(1),@chn nchar(1)
select @strlen=len(@str),@return='',@ii=0
set @ii=0
while @ii<@strlen
begin
select @ii=@ii+1,@chn=substring(@str,@ii,1)
if @chn>='吖'
select @c = char(count(*)+63) from (
select top 27 * from (
select chn = '吖'
union all select '八'
union all select '嚓'
union all select '咑'
union all select '妸'
union all select '发'
union all select '旮'
union all select '铪'
union all select '丌' --because have no 'i'
union all select '丌'
union all select '咔'
union all select '垃'
union all select '嘸'
union all select '拏'
union all select '噢'
union all select '妑'
union all select '七'
union all select '呥'
union all select '仨'
union all select '他'
union all select '屲' --no 'u'
union all select '屲' --no 'v'
union all select '屲'
union all select '夕'
union all select '丫'
union all select '帀'
union all select @chn
) as a
order by chn COLLATE Chinese_PRC_CI_AS ) as b
where b.chn <=@chn
else set @c=@chn
set @return=@return+@c
end
return(@return)
end

标签: sqlServer 获取 汉字 字串 拼音 声母


声明:本文内容来源自网络,文字、图片等素材版权属于原作者,平台转载素材出于传递更多信息,文章内容仅供参考与学习,切勿作为商业目的使用。如果侵害了您的合法权益,请您及时与我们联系,我们会在第一时间进行处理!我们尊重版权,也致力于保护版权,站搜网感谢您的分享!

站长搜索

http://www.adminso.com

Copyright @ 2007~2024 All Rights Reserved.

Powered By 站长搜索

打开手机扫描上面的二维码打开手机版


使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

站长搜索目录系统技术支持