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



  • 相关阅读:
    p1012拼数题解
    LeetCode OJ :Unique Binary Search Trees II(唯一二叉搜索树)
    UVA 11827 Maximum GCD
    LightOJ1336 Sigma Function(约数和为偶数的个数)
    LightOJ 1197 Help Hanzo(区间素数筛选)
    LightOJ 1236
    BZOJ3339 Rmq Problem
    COJ983 WZJ的数据结构(负十七)
    LCA的五种解法
    hdu4223(dp)
  • 原文地址:https://www.cnblogs.com/conan304/p/1657287.html
Copyright © 2011-2022 走看看