当前位置: 首页 > 图文教程 > 数据库 > MYSQL > SQL Server中取汉字拼音的函数

MYSQL
MYSQL教程:新手该看的MYSQL操作
php教程:mysql的常用语句
MySQL5数据导入到MySQL3中的具体操作
PHP+MYSQL网站开发中遇到的问题汇总
WordPress的MySQL连接出错监测方法
MSSQL和Mysql自定义函数与存储过程
PHP+MYSQL网站开发中关于时间的问题
MySQL的1067错误解决方案大全
临时表在SQL Server和MySql中创建的方法
PHP+MYSQL+Flash做留言本
MYSQL5.0家族提供的性能跟踪器
替换数据库某字段的内容:REPLACE函数
PHP删除MYSQL数据库中所有表的代码
怎样解决mysql连接过多的错误?
cannot create windows service for mysql.error:0
MySQL的1067错误解决
如何指定MySQL只监听某个特定地址?
把数据从MySQL迁到Oracle的几点注意事项
MySQL默认密码修改的方法
为MySQL的root用户指定一个目录

MYSQL 中的 SQL Server中取汉字拼音的函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-17   浏览: 64 ::
收藏到网摘: n/a

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

请作者联系本站,及时附注您的姓名。联系邮箱:edu#ruanchen.com(把#改为@)。