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



  • 相关阅读:
    MongoDB的下载与安装
    Oracle PL/SQL 编程手册(SQL大全)
    内部类、异常、其他
    异常(补充)
    final、抽象类、接口、多态、
    改变JVM中的参数以提高Eclipse的运行速度
    Java中的三目运算符 详解
    Java中的Stringbuffer类解析
    Staitic(静态) 相关知识点介绍
    Java反射
  • 原文地址:https://www.cnblogs.com/conan304/p/1657287.html
Copyright © 2011-2022 走看看