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 行)
    */



  • 相关阅读:
    引用 AspNetCoreRateLimit => StatusCode cannot be set because the response has already started.
    Sublime Json 格式化
    gitlab 建立本地仓库
    R语言 启动报错 *** glibc detected *** /usr/lib64/R/bin/exec/R: free(): invalid next size (fast): 0x000000000263a420 *** 错误 解决方案
    范数
    SparkR-Install
    R语言扩展包dplyr——数据清洗和整理
    R语言与机器学习学习笔记
    sparkR原理
    data.frame类型数据如何将第一列值替换为行号
  • 原文地址:https://www.cnblogs.com/conan304/p/1657287.html
Copyright © 2011-2022 走看看