sql 汉字转首字母拼音
从网络上收刮了一些,以备后用
create function fun_getPY(@str nvarchar())
returns nvarchar()
as
begin
declare @word nchar(),@PY nvarchar()
set @PY=''
while len(@str)>
begin
set @word=left(@str,)
--如果非汉字字符,返回原字符
set @PY=@PY+(case when unicode(@word) between and +
then (select top 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)-)
end
return @PY
end
--函数调用实例:
--select dbo.fun_getPY('中华人民共和国')
-----------------------------------------------------------------
--可支持大字符集20000个汉字!
create function f_ch2py(@chn nchar())
returns char()
as
begin
declare @n int
declare @c char()
set @n = select @n = @n +,
@c = case chn when @chn then char(@n) else @c end
from(
select top * 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 select dbo.f_ch2py('中') --Z
select dbo.f_ch2py('国') --G
select dbo.f_ch2py('人') --R
select dbo.f_ch2py('镆') --M
go
-----------------调用
CREATE FUNCTION F_GetHelpCode (
@cName VARCHAR() )
RETURNS VARCHAR()
AS
BEGIN
DECLARE @i SMALLINT, @L SMALLINT , @cHelpCode VARCHAR(), @e VARCHAR(), @iAscii SMALLINT
SELECT @i=, @L= , @cHelpCode=''
while @L<= AND @i<=LEN(@cName) BEGIN
SELECT @e=LOWER(SUBSTRING(@cname,@i,))
SELECT @iAscii=ASCII(@e)
IF @iAscii>= AND @iAscii <= OR @iAscii>= AND @iAscii <= or @iAscii=
SELECT @cHelpCode=@cHelpCode +@e
ELSE
IF @iAscii>= AND @iAscii <=
SELECT @cHelpCode=@cHelpCode + dbo.f_ch2py(@e)
ELSE SELECT @L=@L-
SELECT @i=@i+, @L=@L+ END
RETURN @cHelpCode
END
GO --调用
select dbo.F_GetHelpCode('大力')
------------------------------------------------
/*
函数名称:GetPY
实现功能:将一串汉字输入返回每个汉字的拼音首字母
如输入-->'经营承包责任制'-->输出-->JYCBZRZ.
完成时间:2005-09-18
作者:郝瑞军
参数:@str-->是你想得到拼音首字母的汉字
返回值:汉字的拼音首字母
*/
create function GetPY(@str varchar())
returns varchar()
as
begin
declare @cyc int,@length int,@str1 varchar(),@charcate varbinary()
set @cyc=--从第几个字开始取
set @length=len(@str)--输入汉字的长度
set @str1=''--用于存放返回值
while @cyc<=@length
begin
select @charcate=cast(substring(@str,@cyc,) 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+--取出输入汉字的下一个字
end
return @str1--返回输入汉字的首字母
end
--测试数据
--select dbo.GetPY('从来就是这样酷,我酷,就是酷,看你能把我怎么样,哈哈')
------------------------------------------------------------------
sql 汉字转首字母拼音的更多相关文章
- sql server 利用首字母拼音排序和笔画排序的语句
--按笔画排序 select * from Student order by Sname COLLATE Chinese_PRC_Stroke_CS_AS_KS_WS --按字母拼音排序 select ...
- oracle汉字转拼音(获得全拼/拼音首字母/拼音截取等)
oracle汉字转拼音(获得全拼/拼音首字母/拼音截取等) 效果如下: Oracle 字符集 GBK 没有问题 , UTF -8 需要修改一下 Sql代码 --oracle汉字转拼 ...
- JS实现获取汉字首字母拼音、全拼音及混拼音的方法
本文实例讲述了JS实现获取汉字首字母拼音.全拼音及混拼音的方法.分享给大家供大家参考,具体如下: 这里需要用到一个js获取汉字拼音的插件,可点击此处本站下载. 运行效果如下: 完整示例代码: ? 1 ...
- SQLSERVER中汉字提取首字母的拼音函数的实现
--创建一个汉字提取首字母的函数--还存在一点小小的问题(符号?)create function hs(@a varchar(1000)='')returns varchar(1000)asbegin ...
- Android -- 获取汉字的首字母
转换 获取一个汉 ...
- 终结者:借助pinyin4j相关jar包提取汉字的首字母
import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j.format.HanyuPinyinCase ...
- Code:获取指定汉字的首字母
ylbtech-Code:获取指定汉字的首字母 1.获取指定汉字的首字母返回顶部 1. /// <summary> /// 获取指定汉字的首字母 /// </summary> ...
- C# 常用类库(字符串处理,汉字首字母拼音,注入攻击,缓存操作,Cookies操作,AES加密等)
十年河东,十年河西,莫欺少年穷 学无止境,精益求精 记录下字符串类库,方便今后查阅 主要包含了字符串解决,去除HTML,SQL注入攻击检测,IP地址处理,Cookies操作,根据身份证获取性别.姓名. ...
- c#获取汉字首字母拼音
/* * 由SharpDevelop创建. * 用户: lenovo * 日期: 2013/10/22 * 时间: 20:15 * * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件 */ ...
随机推荐
- Codeforces 716A Crazy Computer 【模拟】 (Codeforces Round #372 (Div. 2))
A. Crazy Computer time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- C#代码实现隐藏任务栏、开始菜单和禁用任务管理
一:截图,主要是调用系统接口和更改注册表实现功能 二:代码 using System; using System.Collections.Generic; using System.Linq; usi ...
- 读《细说php》,php要点随记
近期读<细说php>,其实知识要点都接触过,体会下不同书籍对相同知识的描述差异,达到温故知心的目的. 未按章节顺序读,所谓要点并不是提纲式的所有要点,只是自己觉得工作中很重要(但是掌握的不 ...
- HTTP协议之状态码详解
转自:http://www.cnblogs.com/TankXiao/ 什么是HTTP状态码 HTTP状态码的作用是:Web服务器用来告诉客户端,发生了什么事. 状态码位于HTTP Response ...
- 【Python爬虫】安装 pyQuery 遇到的坑 Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
windows 64位操作系统下,用 Python 抓取网页,并用 pyQuery 解析网页 pyQuery是jQuery在python中的实现,能够以jQuery的语法来操作解析HTML文档,十分方 ...
- JS 操作 HTML 自定义属性
<input type="text" id="txtBox" displayName="123456" /> 获取自定义属性值: ...
- ld: 18 duplicate symbols for architecture i386 .linker command failed with exit code 1 (use -v to see invocation)_
昨天被linker这个错误卡了一个小时!!!各种办法都试了 是导入第三方的问题 .. 网上说 要把所有的.m文件导入 但是我下载的微博SDK根本不关事..后来 大概知道是导入了多个相同的文件... ...
- iOS iOS8新特性--UIPopoverPresentationController
1.回顾UIPopoverController的使用,下面这份代码只能在ipad下运行 // 初始化控制器,SecondViewController类继承自UIViewController Secon ...
- POJ 1986(LCA and RMQ)
题意:给定一棵树,求任意两点之间的距离. 思路:由于树的特殊性,所以任意两点之间的路径是唯一的.u到v的距离等于dis(u) + dis(v) - 2 * dis(lca(u, v)); 其中dis( ...
- 中国剩余定理模板poj1006
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #i ...