• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

获得汉字字符串的首字母

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 18次 | 进入软件测试论坛讨论

领测软件测试网 --*/
if exists (select * from dbo.sysobjects where id = object_id(N‘’[dbo].[fGetPy]‘’) and xtype in (N‘’FN‘’, N‘’IF‘’, N‘’TF‘’))
drop function [dbo].[fGetPy]
GO

--创建取拼音函数
create function fGetPy(@Str varchar(500)=‘’‘’)
returns varchar(500)
as
begin
    declare @strlen int,@return varchar(500),@ii int
    declare @n int,@c char(1),@chn nchar(1)

    select @strlen=len(@str),@return=‘’‘’,@ii=0
    set @ii=0
    while @ii<@strlen
    begin
        select @ii=@ii+1,@n=63,@chn=substring(@str,@ii,1)
        if @chn>‘’z‘’
        select @n = @n +1
                    ,@c = case chn when @chn then char(@n) else @c end
            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
        else set @c=‘’a‘’
        set @return=@return+@c
    end
    return(@return)
end

go
--测试
select dbo.fgetpy(‘’魏保光‘’) as 姓名拼音,dbo.fgetpy(‘’ab中c国人‘’) as 中国人
select dbo.fgetpy(‘’刘子良‘’) as 姓名拼音,dbo.fgetpy(‘’ab中c国人‘’) as 中国人
select dbo.fgetpy(‘’吴过‘’) as 姓名拼音,dbo.fgetpy(‘’ab中c国人‘’) as 中国人
select dbo.fgetpy(‘’东北‘’) as 姓名拼音,dbo.fgetpy(‘’ab中c国人‘’) as 中国人

--删除拼音函数
drop function fgetpy

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网