编程论坛's Archiver

wsn 发表于 2006-3-7 11:05

贡献一段汉字转拼音码的函数

<P>--取出汉字的拼音首码<BR>--入参:汉字字符串<BR>--出参:汉字字符串首拼音码<BR>CREATE  function Fun_GetPY <BR> ( <BR>    @str nvarchar(4000) <BR> ) <BR>returns nvarchar(4000) <BR>as <BR>begin </P>
<P>  declare @word nchar(1),@PY nvarchar(4000) </P>
<P>  set @PY='' </P>
<P>  while len(@str)&gt;0 <BR>  begin <BR>    set @word=left(@str,1) </P>
<P>    --如果非汉字字符,返回原字符 <BR>    set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901 <BR>               then (  <BR>                            select top 1 PY  <BR>                            from  <BR>                            (  <BR>                             select 'A' as PY,N'驁' as word <BR>                             union all select 'B',N'簿' <BR>                             union all select 'C',N'錯' <BR>                     union all select 'D',N'鵽' <BR>                     union all select 'E',N'樲' <BR>                     union all select 'F',N'鰒' <BR>                     union all select 'G',N'腂' <BR>                     union all select 'H',N'夻' <BR>                     union all select 'J',N'攈' <BR>                     union all select 'K',N'穒' <BR>                     union all select 'L',N'鱳' <BR>                     union all select 'M',N'旀' <BR>                     union all select 'N',N'桛' <BR>                     union all select 'O',N'漚' <BR>                     union all select 'P',N'曝' <BR>                     union all select 'Q',N'囕' <BR>                     union all select 'R',N'鶸' <BR>                     union all select 'S',N'蜶' <BR>                     union all select 'T',N'籜' <BR>                     union all select 'W',N'鶩' <BR>                     union all select 'X',N'鑂' <BR>                     union all select 'Y',N'韻' <BR>                     union all select 'Z',N'咗' <BR>                      ) T  <BR>                   where word&gt;=@word collate Chinese_PRC_CS_AS_KS_WS  <BR>                   order by PY ASC <BR>                          )  <BR>                      else @word  <BR>                 end) <BR>    set @str=right(@str,len(@str)-1) <BR>  end </P>
<P>  return @PY </P>
<P>end</P>

wsn 发表于 2006-3-7 11:20

顶啊

wsn 发表于 2006-3-7 16:39

没有人要用这个东西吗,做系统时要用的

LouisXIV 发表于 2006-3-7 17:18

不错,偶给加个精(这个论坛的处女精)[em05]

wsn 发表于 2006-3-8 11:05

谢主隆恩<BR><BR>

zhaofeng701 发表于 2006-3-8 16:51

<P>谢谢!<BR></P>

zhou 发表于 2008-3-30 11:50

*** 作者被禁止或删除 内容自动屏蔽 ***

Saber0227 发表于 2008-4-1 12:54

函数不会用
LZ能给个用这个函数的例题吗?
先谢谢了。

shezhenhui1989 发表于 2008-4-1 12:55

谢谢楼主啊

jxyga111 发表于 2008-5-13 18:43

還行

happynight 发表于 2008-5-14 08:44

好东西 收藏了 谢谢

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.