sql语句 汉字转拼音首字母
(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语句 汉字转拼音首字母的更多相关文章
- sql获取汉字的拼音首字母的函数
ql获取汉字的拼音首字母 if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and ...
- sql获取汉字的拼音首字母
if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and xtype in (N'FN' ...
- sql server 汉字转拼音首字母
create function fun_getPY ( @str nvarchar(4000) ) returns nvarchar(4000) as begin declare @word ncha ...
- js汉字转拼音首字母
js汉字转拼音首字母 2018-04-09 阅读 1018 收藏 1 原链:segmentfault.com 分享到: 前端必备图书<JavaScript设计模式与开发实践> > ...
- (转载)delphi中获取汉字的拼音首字母
delphi中获取汉字的拼音首字母1.py: array[216..247] of string = ({216}'CJWGNSPGCGNESYPB' + 'TYYZDXYKYGTDJNMJ' + ' ...
- SqlServer 汉字转换拼音首字母函数
CREATE function [dbo].[Func_GetPY](@str nvarchar(4000))returns nvarchar(4000)asbegin set @str=RTRIM( ...
- 简单测试--C#实现中文汉字转拼音首字母
第一种: 这个是自己写的比较简单的实现方法,要做汉字转拼音首字母,首先应该有一个存储首字母的数组,然后将要转拼音码的汉字与每个首字母开头的第一个汉字即“最小”的汉字作比较,这里的最小指的是按拼音规则比 ...
- 汉字转拼音首字母的java实现
工作中经常会遇到的一些排序问题,比如 按汉字的拼音首字母排序,比如人名排序等,就要用到下面的方法了,思路: 1. 获得汉字 2. 将汉字转换成首字母,并记录下(必要时保存到数据库) 3. 按首字母进行 ...
- C#获取包括一二级汉字的拼音 首字母
C#获取包括一二级汉字的拼音 首字母 声母 汉字拼音转换 using System; using System.Collections.Generic; using System.Linq; usin ...
随机推荐
- 通过VirtualBox安装Linux系统(CentOS7)
本文目的:创建虚拟系统.在windows系统中通过虚拟工具VirtualBox创建一个虚拟系统CentOS. 备注:(1)版本如下:VirtualBox-5.2.12-122591-Win 和Cent ...
- How nginx "location if" works
Nginx's if directive does have some weirdness in practice. And people may misuse it when they do not ...
- Tomcat9使用免费的Https证书加密网站
1.概述 Apache Tomcat是一款优秀的Java Web容器,对于各个站长来说,可以很方便的使用Tomcat将自己的网站博客放在公网的服务器上,分享自己的心得以及个人博客. 那么在公网中的访问 ...
- junit+mock+spring-test构建后台单元测试
from:从0开始,构建前后端分离应用 1. 一些基本概念 1.1 为什么要进行单元测试?我自己的理解是 1.能够快速发现问题.避免衍生BUG的出现 在对一些现有代码进行修改时,或者修改现有B ...
- HEOI2018 游记
day0早上没有跑操,收拾了点东西,带了点吃的,老妈打电话说要给送点厚衣服,好像确实有点冷.上午有考试,说自愿考,然后开到一半就没了,根本没人打啊,打了一道小园丁和老司机,一个一个部分分打,最后T了一 ...
- bzoj2437 [Noi2011]兔兔与蛋蛋
二分图博弈果然都是一个套路,必经点必胜,非必经点必败, 但是肯定不能每走一步就重新建图判断必胜还是必败,那么我们可以这样:每走一步就把这个点删掉,然后find他原来的匹配,如果找不到,就说明他是必经点 ...
- 视频转字符动画-Python-60行代码
更新:2018-5-21 注意: 最后一步播放字符动画使用了只支持类 unix 系统的模块 curses, 因此在windows上是播放不了的... 解决方法: 1. 最近好像有一个移植 https: ...
- ply python 图片压缩 图片裁剪 旋转
http://tech.seety.org/python/python_imaging.html
- 移动通信最先进的音频编解码器EVS及用好要做的工作
语音通信从最初的只有有线通信变成后来的有线通信与无线通信(移动通信)的竞争,当移动语音通信价格下来后有线语音通信明显处于逆势.如今移动语音通信的竞争对手是OTT(On The Top)语音,OTT语音 ...
- jdk源码阅读笔记-LinkedHashMap
Map是Java collection framework 中重要的组成部分,特别是HashMap是在我们在日常的开发的过程中使用的最多的一个集合.但是遗憾的是,存放在HashMap中元素都是无序的, ...