zoukankan      html  css  js  c++  java
  • SqlServer的汉字转拼音码的函数

    代码
    --
    --
     Definition for user-defined function f_GetPy : 
    --
    GO
    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

    代码
    //用法一
    string sql = string.Format("Name like '%{0}%' or dbo.f_GetPy(Name) like '{0}%' ", goodsName);

    //用法二
    string sql = string.Format(@"Select * from (Select Company_Name from tb_enterprise where Company_Name like '%{1}%' or F_PINYIN(Company_Name) like '%{1}%' ) 
                                             WHERE ROWNUM <= {0} ORDER BY ROWNUM ASC
    ", topCount, name);
  • 相关阅读:
    Android获取视频音频的时长的方法
    Android动画效果之Frame Animation(逐帧动画)
    去除自定义Toolbar中左边距
    Android Toolbar样式定制详解
    Android 5.x Theme 与 ToolBar 实战
    Android ToolBar 使用完全解析
    Android开发:最详细的 Toolbar 开发实践总结
    SpannableString 转换局部字体大小,但在EditText测量之前设置内容,测量高度为,字体变小之前的高度
    android在Service中弹出Dialog对话框,即全局性对话框
    Could not find com.android.tools.build:gradle:3.0.0-alpha3
  • 原文地址:https://www.cnblogs.com/kokoliu/p/1657784.html
Copyright © 2011-2022 走看看