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



  • 相关阅读:
    VUE学习日记(十八) ---- 传递数据
    VUE学习日记(十七) ---- 组件数据函数
    VUE学习日记(十六) ---- 表行组件
    DataGridView控件使用Demo
    C# ADO.NET连接字符串详解
    SQL Server management studio使用sa连接时报错与伺服器的连接已成功,但在登入程序是发生错误
    Oracle Rac to Rac One Node
    online创建索引中途取消导致索引无法删除解决办法
    oracle常用hint添加
    C# url的编码解码,xml和json的序列化和反序列化
  • 原文地址:https://www.cnblogs.com/conan304/p/1657287.html
Copyright © 2011-2022 走看看