(1)-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

create function GetPY(@str varchar(500))
returns varchar(500)
as
begin
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=cast(substring(@str,@cyc,1) as varbinary)--每次取出一个字并将其转变成二进制,便于与GBK编码表进行比较
if @charcate>=0XB0A1 and @charcate<=0XB0C4
set @str1=@str1+'A'--说明此汉字的首字母为A,以下同上
else if @charcate>=0XB0C5 and @charcate<=0XB2C0
set @str1=@str1+'B'
else if @charcate>=0XB2C1 and @charcate<=0XB4ED
set @str1=@str1+'C'
else if @charcate>=0XB4EE and @charcate<=0XB6E9
set @str1=@str1+'D'
else if @charcate>=0XB6EA and @charcate<=0XB7A1
set @str1=@str1+'E'
else if @charcate>=0XB7A2 and @charcate<=0XB8C0
set @str1=@str1+'F'
else if @charcate>=0XB8C1 and @charcate<=0XB9FD
set @str1=@str1+'G'
else if @charcate>=0XB9FE and @charcate<=0XBBF6
set @str1=@str1+'H'
else if @charcate>=0XBBF7 and @charcate<=0XBFA5
set @str1=@str1+'J'
else if @charcate>=0XBFA6 and @charcate<=0XC0AB
set @str1=@str1+'K'
else if @charcate>=0XC0AC and @charcate<=0XC2E7
set @str1=@str1+'L'
else if @charcate>=0XC2E8 and @charcate<=0XC4C2
set @str1=@str1+'M'
else if @charcate>=0XC4C3 and @charcate<=0XC5B5
set @str1=@str1+'N'
else if @charcate>=0XC5B6 and @charcate<=0XC5BD
set @str1=@str1+'O'
else if @charcate>=0XC5BE and @charcate<=0XC6D9
set @str1=@str1+'P'
else if @charcate>=0XC6DA and @charcate<=0XC8BA
set @str1=@str1+'Q'
else if @charcate>=0XC8BB and @charcate<=0XC8F5
set @str1=@str1+'R'
else if @charcate>=0XC8F6 and @charcate<=0XCBF9
set @str1=@str1+'S'
else if @charcate>=0XCBFA and @charcate<=0XCDD9
set @str1=@str1+'T'
else if @charcate>=0XCDDA and @charcate<=0XCEF3
set @str1=@str1+'W'
else if @charcate>=0XCEF4 and @charcate<=0XD1B8
set @str1=@str1+'X'
else if @charcate>=0XD1B9 and @charcate<=0XD4D0
set @str1=@str1+'Y'
else if @charcate>=0XD4D1 and @charcate<=0XD7F9
set @str1=@str1+'Z'
set @cyc=@cyc+1--取出输入汉字的下一个字
end
return @str1--返回输入汉字的首字母
end

(2)--------------------------------------------------------------------------------------------------------------------------------------------

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

sql语句 汉字转拼音首字母的更多相关文章

  1. sql获取汉字的拼音首字母的函数

    ql获取汉字的拼音首字母   if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and ...

  2. sql获取汉字的拼音首字母

    if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and xtype in (N'FN' ...

  3. sql server 汉字转拼音首字母

    create function fun_getPY ( @str nvarchar(4000) ) returns nvarchar(4000) as begin declare @word ncha ...

  4. js汉字转拼音首字母

    js汉字转拼音首字母 2018-04-09 阅读 1018 收藏 1 原链:segmentfault.com 分享到:   前端必备图书<JavaScript设计模式与开发实践> > ...

  5. (转载)delphi中获取汉字的拼音首字母

    delphi中获取汉字的拼音首字母1.py: array[216..247] of string = ({216}'CJWGNSPGCGNESYPB' + 'TYYZDXYKYGTDJNMJ' + ' ...

  6. SqlServer 汉字转换拼音首字母函数

    CREATE function [dbo].[Func_GetPY](@str nvarchar(4000))returns nvarchar(4000)asbegin set @str=RTRIM( ...

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

    第一种: 这个是自己写的比较简单的实现方法,要做汉字转拼音首字母,首先应该有一个存储首字母的数组,然后将要转拼音码的汉字与每个首字母开头的第一个汉字即“最小”的汉字作比较,这里的最小指的是按拼音规则比 ...

  8. 汉字转拼音首字母的java实现

    工作中经常会遇到的一些排序问题,比如 按汉字的拼音首字母排序,比如人名排序等,就要用到下面的方法了,思路: 1. 获得汉字 2. 将汉字转换成首字母,并记录下(必要时保存到数据库) 3. 按首字母进行 ...

  9. C#获取包括一二级汉字的拼音 首字母

    C#获取包括一二级汉字的拼音 首字母 声母 汉字拼音转换 using System; using System.Collections.Generic; using System.Linq; usin ...

随机推荐

  1. Cookie与 Session使用详解

    Cookie概念 在浏览某些 网站 时,这些网站会把 一些数据存在 客户端 , 用于使用网站 等跟踪用户,实现用户自定义 功能. 是否设置过期时间: 如果不设置 过期时间,则表示这个 Cookie生命 ...

  2. mybatis的使用

    1.like 的使用范例 name like CONCAT(CONCAT('%', #{name}), '%') 2.时间的比较的范例 <![CDATA[ and bill_date >= ...

  3. ActiveMQ的使用

    ActiveMQ使用分为两大块:生产者和消费者 一.准备 项目导入jar包:activemq-all-5.15.3.jar 并buildpath    二.生产者 创建连接工厂 ActiveMQCon ...

  4. jQuery学习之旅 Item8 DOM事件操作

    1.jquery页面载入事件 1.传统加载事件 <body onload="函数名()"> 页面全部html和css代码加载完成之后再调用指定的onload函数 win ...

  5. 巩固java(五)----通过实例理解java多态

    package duotai; class A{ public String show(){ return "A"; } } class B extends A{ public S ...

  6. 聊一聊promise的前世今生

    promise的概念已经出现很久了,浏览器.nodejs都已经全部实现promise了.现在来聊,是不是有点过时了? 确实,如果不扯淡,这篇随笔根本不会有太多内容.所以,我就尽可能的,多扯一扯,聊一聊 ...

  7. JS代码检查工具ESLint

    前面的话 ESLint是一个JavaScript代码静态检查工具,可以检查JavaScript的语法错误,提示潜在的bug,可以有效提高代码质量,维持前端团队高度一致的编码风格.ESLint不但提供一 ...

  8. [SCOI2005]栅栏 二分+dfs

    这个题真的是太nb了,各种骚 二分答案,肯定要减最小的mid个,从大往小搜每一个木板,从大往小枚举所用的木材 当当前木材比最短的木板还短,就扔到垃圾堆里,并记录waste,当 waste+sum> ...

  9. Evensgn 剪树枝 树规

    f[x][0]表示与其父边相连的连通块内没有黑苹果的方案数, f[x][1]则表示有黑苹果, 如果父边被切断,相当于没有黑苹果 初始化时,假设切掉父边,f[x][0]=1,f[x][1]=0; 递归回 ...

  10. 什么是语义化的HTML?为什么要做到语义化?

    一.什么是语义化的HTML? 语义化的HTML就是写出的HTML代码,符合内容的结构化(内容语义化),选择合适的标签(代码语义化),能够便于开发者阅读和写出更优雅的代码的同时让浏览器的爬虫和机器很好地 ...