获取中文名称的首字母
发布时间:2020-05-23 08:46:55 所属栏目:MySql 来源:互联网
导读:获取中文名称的首字母
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 CREATE FUNCTION getPinYin (@str varchar(500) = '')
RETURNS varchar(500) AS
/*-------------------用于获取中文名称的首字母---------------------------------*/
BEGIN
Declare @strlen int,@return varchar(500),@ii int,@c char(1),@chn nchar(1)
--//初始化变量
Declare @pytable table(
chn char(2) COLLATE Chinese_PRC_CS_AS NOT NULL,py char(1) COLLATE Chinese_PRC_CS_AS NULL,PRIMARY KEY (chn)
)
insert into @pytable values('吖','A')
insert into @pytable values('八','B')
insert into @pytable values('嚓','C')
insert into @pytable values('咑','D')
insert into @pytable values('妸','E')
insert into @pytable values('发','F')
insert into @pytable values('旮','G')
insert into @pytable values('铪','H')
--insert into @pytable values('丌','I')
insert into @pytable values('丌','J')
insert into @pytable values('咔','K')
insert into @pytable values('垃','L')
insert into @pytable values('嘸','M')
insert into @pytable values('拏','N')
insert into @pytable values('噢','O')
insert into @pytable values('妑','P')
insert into @pytable values('七','Q')
insert into @pytable values('呥','R')
insert into @pytable values('仨','S')
insert into @pytable values('他','T')
--insert into @pytable values('屲','U')
--insert into @pytable values('屲','V')
insert into @pytable values('屲','W')
insert into @pytable values('夕','X')
insert into @pytable values('丫','Y')
insert into @pytable values('帀','Z')
select @strlen = len(@str),@return = '',@ii = 0
--//循环整个字符串,用拼音的首字母替换汉字
while @ii < @strlen
begin
select @ii = @ii + 1,@chn = substring(@str,@ii,1)
if @chn > 'z' --//检索输入的字符串中有中文字符
SELECT @c = max(py)
FROM @pytable
where chn <= @chn
else
set @[emailprotected]
set @[emailprotected][emailprotected]
end
return @return
END
以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读
