zoukankan      html  css  js  c++  java
  • SQL SERVER取得汉字的拼音缩写

    原文在此,http://www.cnblogs.com/wuhuacong/archive/2010/01/25/1655916.html


    代码
    /*
    取得汉字的拼音缩写
    */
    CREATE function [dbo].f_GetPy
    (
        
    @str nvarchar(4000)

    returns nvarchar(4000
    as 
    begin 
        
    declare @strlen int,@re nvarchar(4000
        
    declare @t table(chr nchar(1) collate Chinese_PRC_CI_AS,letter nchar(1)) 
        
    insert into @t(chr,letter) 
          
    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 '嘸 ''' 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 '帀 ''' 

          
    select @strlen=len(@str),@re= ' ' 
          
    while @strlen> 0 
          
    begin 
            
    select top 1 @re=letter+@re,@strlen=@strlen-1 
            
    from @t a where chr <=substring(@str,@strlen,1
            
    order by chr desc 
            
    if @@rowcount=0 
            
    select @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1 
          
    end 
          
    return(@re
    end

    执行结果:

    select dbo.f_GetPy('博客园')
    /*
                        
    ------------------- 
    BKY 

    (所影响的行数为 1 行)
    */



  • 相关阅读:
    python汉诺塔
    圆周率计算
    PIL: 建立一个GIF图
    Jieba库使用和好玩的词云
    Turtle库的建立——汉诺塔
    计算pi的精度+进度条显示
    Python——我所学习的turtle函数库
    Python——教你画朵太阳花
    Python常用模块re的使用
    正则表达式字符组/元字符/量词
  • 原文地址:https://www.cnblogs.com/conan304/p/1657287.html
Copyright © 2011-2022 走看看