CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  MS-SQL Server >  应用实例

怎样写SQL函数汉字转换拼音简码

楼主qiudongbao(我走我路)2005-06-04 18:31:27 在 MS-SQL Server / 应用实例 提问

我想定义一个函数对字段中汉字更新为拼音简码(多个汉字),但是下面这段函数只能对第一个汉字转换。有哪位高手帮帮忙写一个能转换多个汉字的函数,修改下面的函数也可。  
  create   function   f_ch2py(@chn   nchar(1))   /*nchar固定长度的   Unicode   数据*/  
  returns   char(1)  
  as  
  begin  
  declare   @n   int  
  declare   @c   char(1)  
  set   @n   =   63  
  select   @n   =   @n   +1,  
  @c   =   case   chn   when   @chn   then   char(@n)   else   @c   end  
  from(  
  select   top   27   *   from   (  
  select   chn   =    
  '吖'   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   --because   have   no   'i'  
  '丌'   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   --no   'u'  
  '屲'   union   all   select   --no   'v'  
  '屲'   union   all   select  
  '夕'   union   all   select  
  '丫'   union   all   select  
  '帀'   union   all   select   @chn)   as   a  
  order   by   chn   COLLATE   Chinese_PRC_CI_AS    
  )   as   b  
  return(@c)  
  end  
  go 问题点数:0、回复次数:2Top

1 楼ReViSion(和尚)回复于 2005-06-04 18:41:45 得分 0

多的有卖呀,自己搜一下Top

2 楼wdwlbsm1(毛一丁)回复于 2005-06-07 17:30:14 得分 0

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

相关问题

  • SQL 函数
  • [函数]我这样数汉字
  • sql函数问题
  • sql函数问题
  • SQL的sum函数?
  • 求:输入汉字,自动输出拼音简码的现成JAVA代码
  • sql的日期函数;
  • 菜鸟求教sql函数
  • SQL SERVER函数问题?
  • 简单的sql函数

关键词

  • 函数
  • 汉字
  • chn
  • union all select
  • char
  • select

得分解答快速导航

  • 帖主:qiudongbao

相关链接

  • SQL Server类图书

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo