• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#、Oracle、Sqlserver中拼音查询的函数

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
C# sqlserver oracle 的都有 不过发现那个 C# 的好像"楠"字查的时候会有问题。。。不知道为啥。。

C#

  1 

Oracle

 1create or replace function fGetPy
 2(V_Str varchar2)
 3return varchar2 
 4as        
 5  v_strlen int;
 6  v_return varchar2(500);
 7  v_ii int    ;
 8  v_n int;
 9  v_c char(1);
10  v_chn varchar2(2);
11  V_RC varchar2(500);
12begin
13 V_RC:=V_Str;
14
15 v_strlen :=len(V_RC);
16 v_return := '';
17 v_ii:=0
18 while v_ii<v_strlen loop    
19  v_ii:=v_ii+1;
20  v_n:=63;
21  SELECT substring(V_RC,v_ii,1INTO v_chn FROM DUAL;
22
23
24  select v_n+max(rowsf) into v_n
25   from
26   select chn,ROWNUM rowsf from(   
27    select chn from (    
28     select ''  chn  from dual
29     union  select ''   from dual 
30     union all  select ''  from dual  
31     union all  select ''   from dual 
32     union all  select ''    from dual
33     union all select ''    from dual
34     union all select ''   from dual 
35     union all select ''   from dual 
36     union all select ''  from dual--because have no 'i'    
37     union all select ''   from dual 
38     union all select ''    from dual
39     union all select ''   from dual 
40     union all select ''   from dual 
41     union all select ''    from dual
42     union all select ''   from dual 
43     union all select ''   from dual 
44     union all select ''   from dual 
45     union all select ''    from dual
46     union all select ''    from dual
47     union all select ''    from dual
48     union all select ''  from dual   
49     union all select ''  from dual    
50     union all select '' from dual   
51     union all select ''  from dual  
52     union all select ''  from dual  
53     union all select ''    from dual
54     union all select v_chn from dual
55     )  a    
56   order by nlssort(chn,'NLS_SORT=SCHINESE_PINYIN_M'
57   ) c
58    )  b WHERE chn=v_chn ;
59
60   
61  v_c:=chr(v_n);
62  if chr(v_n) ='@' then--英文直接返回    
63   v_c:=v_chn    ;
64   end if;
65   
66 
67  v_return:=v_return||v_c;
68 end loop; 
69 
70 return v_return;    
71end;

sql server

 1create   function   fGetPy(@Str   varchar(500)='')   
 2  returns   varchar(500)   
 3  as   
 4  begin   
 5  declare   @strlen   int,@return   varchar(500),@ii   int   
 6  declare   @n   int,@c   char(1),@chn   nchar(1)   
 7    
 8  select   @strlen=len(@str),@return='',@ii=0   
 9  set   @ii=0   
10  while   @ii<@strlen   
11  begin   
12  select   @ii=@ii+1,@n=63,@chn=substring(@str,@ii,1)   
13  select   @n   =   @n   +1   
14  ,@c   =   case   chn   when   @chn   then   char(@n)   else   @c   end   
15  from(   
16  select   top   27   *   from   (   
17  select   chn   =   ''   
18  union   all   select   ''   
19  union   all   select   ''   
20  union   all   select   ''   
21  union   all   select   ''   
22  union   all   select   ''   
23  union   all   select   ''   
24  union   all   select   ''   
25  union   all   select   '' --because   have   no   'i'   
26  union   all   select   ''   
27  union   all   select   ''   
28  union   all   select   ''   
29  union   all   select   ''   
30  union   all   select   ''   
31  union   all   select   ''   
32  union   all   select   ''   
33  union   all   select   ''   
34  union   all   select   ''   
35  union   all   select   ''   
36  union   all   select   ''   
37  union   all   select   '' --no   'u'   
38  union   all   select   '' --no   'v'   
39  union   all   select   ''   
40  union   all   select   ''   
41  union   all   select   ''   
42  union   all   select   ''   
43  union   all   select   @chn)   as   a   
44  order   by   chn   COLLATE   Chinese_PRC_CI_AS     
45  )   as   b   
46  set   @return=@return+@c   
47  end   
48  return(@return)   
49  end

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#类发布时间:2022-07-10
下一篇:
(c#)WinForm遍历所有控件发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap