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);
  • 相关阅读:
    合并两个有序数组
    删除排序数组中的重复项 II
    对称二叉树
    相同的树
    二叉树的最大深度
    从前序与中序遍历序列构造二叉树
    vue简单案例_动态添加删除用户数据
    对vue的初步学习(一)
    关于java for循环常见练习题
    关于java中循环的学习
  • 原文地址:https://www.cnblogs.com/kokoliu/p/1657784.html
Copyright © 2011-2022 走看看