sql server 汉字转拼音首字母

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 @[email protected]+(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

sql server 汉字转拼音首字母

时间: 2024-07-29 00:22:51

sql server 汉字转拼音首字母的相关文章

sql获取汉字的拼音首字母

if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and xtype in (N'FN', N'IF', N'TF')) www.2cto.com drop function [fn_ChineseToSpell]GO/*创建取拼音首字母函数*/ create function [dbo].[fn_ChineseToSpell](@strChinese varchar(500)='')

SQL Server 字段提取拼音首字母

目前工作中遇到一个情况,需要将SQL Server中的一个字段提取拼音的首字母,字段由汉字.英文.数字以及“-”构成,百度了一堆,找到如下方法,记录一下,以备后用! 首先建立一个函数 --生成拼音首码 CREATE function fn_GetPy(@str nvarchar(4000)) returns nvarchar(4000) --WITH ENCRYPTION as begin declare @intLen int declare @strRet nvarchar(4000) de

sql语句 汉字转拼音首字母

create function GetPY(@str varchar(500))returns varchar(500)asbegin declare @cyc int,@length int,@str1 varchar(100),@charcate varbinary(20) set @cyc=1--从第几个字开始取 set @length=len(@str)--输入汉字的长度 set @str1=''--用于存放返回值 while @cyc<=1 begin select @charcate

ios汉字转拼音首字母

ios汉字转拼音首字母 //获取拼音首字母(传入汉字字符串, 返回大写拼音首字母) - (NSString *)firstCharactor:(NSString *)aString { //转成了可变字符串 NSMutableString *str = [NSMutableString stringWithString:aString]; //先转换为带声调的拼音 CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransform

简单测试--C#实现中文汉字转拼音首字母

第一种: 这个是自己写的比较简单的实现方法,要做汉字转拼音首字母,首先应该有一个存储首字母的数组,然后将要转拼音码的汉字与每个首字母开头的第一个汉字即"最小"的汉字作比较,这里的最小指的是按拼音规则比较最小,例如a比h小,所以"爱"比"恨"小,同一个字母开头的拼音比较大小以此类推.最后实现的结果是只转汉字,对于中文特殊字符.标点符号和英文都原样输出,不转码. 实现方法如下: 1 using System; 2 using System.Colle

C# 获取汉字的拼音首字母(转)

原文:https://blog.csdn.net/younghaiqing/article/details/62417269 一种是把所有中文字符集合起来组成一个对照表:另一种是依照汉字在Unicode编码表中的排序来确定拼音的首字母.碰到多音字时就以常用的为准(第一种方法中可以自行更改,方法为手动把该汉字移动到对应的拼音首字母队列,我们这里介绍第二种. 获取汉字拼音的首字母是一个在做项目的过程中经常需要用到的功能,今天我们主要来探讨下C# 获取汉字的拼音首字母 static void Main

mysql数据库中查询汉字的拼音首字母

本人提供的方法有如下特点: 1.代码精简,使用简单,只要会基本的SQL语句就行2.不用建立mysql 函数等复杂的东西3.汉字库最全,可查询20902个汉字方法如下:1.建立拼音首字母资料表Sql代码:(最好再加上主键和索引) DROP TABLE IF EXISTS `pinyin`; CREATE TABLE `pinyin` ( `PY` varchar(1), `HZ1` varchar(1), `HZ2` varchar(1) ) ; INSERT   INTO   `pinyin` 

汉字转拼音首字母

输入汉字,提取其首字母: /// <summary> /// 汉字转拼音缩写 /// Code By /// 2004-11-30 /// </summary> /// <param name="str">要转换的汉字字符串</param> /// <returns>拼音缩写</returns> public string GetPYString(string str) { string tempStr = &qu

C# 获取汉字的拼音首字母

/// <summary> /// 在指定的字符串列表CnStr中检索符合拼音索引字符串 /// </summary> /// <param name="CnStr">汉字字符串</param> /// <returns>相对应的汉语拼音首字母串</returns> public static string GetSpellCode(string CnStr) { string strTemp="&quo