从网络上收刮了一些,以备后用

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
--函数调用实例:
--select dbo.fun_getPY('中华人民共和国')
-----------------------------------------------------------------
--可支持大字符集20000个汉字!
create   function   f_ch2py(@chn   nchar(1))  returns   char(1)  as  begin  declare   @n   int  declare   @c   char(1)  set   @n   =   63  select   @n   =   @n   +1,  @c   =   case   chn   when   @chn   then   char(@n)   else   @c   end  from(  select   top   27   *   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(20)   )  RETURNS   VARCHAR(12)  AS  BEGIN  DECLARE   @i   SMALLINT,   @L   SMALLINT   ,   @cHelpCode   VARCHAR(12),   @e   VARCHAR(12),   @iAscii   SMALLINT  SELECT   @i=1,   @L=0   ,   @cHelpCode=''  while   @L<=12   AND   @i<=LEN(@cName)   BEGIN  SELECT   @e=LOWER(SUBSTRING(@cname,@i,1))  SELECT   @iAscii=ASCII(@e)  IF   @iAscii>=48   AND   @iAscii   <=57   OR   @iAscii>=97   AND   @iAscii   <=122   or   @iAscii=95    SELECT   @cHelpCode=@cHelpCode     +@e  ELSE  IF   @iAscii>=176   AND   @iAscii   <=247  SELECT   @cHelpCode=@cHelpCode     +   dbo.f_ch2py(@e)  ELSE   SELECT   @L=@L-1  SELECT   @i=@i+1,   @L=@L+1   END    RETURN   @cHelpCode  END  GO  --调用  select   dbo.F_GetHelpCode('大力')
------------------------------------------------
/*函数名称:GetPY实现功能:将一串汉字输入返回每个汉字的拼音首字母 如输入-->'经营承包责任制'-->输出-->JYCBZRZ.完成时间:2005-09-18作者:郝瑞军参数:@str-->是你想得到拼音首字母的汉字返回值:汉字的拼音首字母
*/
create function GetPY(@str varchar(500))
returns varchar(500)
as
begindeclare @cyc int,@length int,@str1 varchar(100),@charcate varbinary(20)set @cyc=1--从第几个字开始取set @length=len(@str)--输入汉字的长度set @str1=''--用于存放返回值while @cyc<=@lengthbegin  select @charcate=cast(substring(@str,@cyc,1) as varbinary)--每次取出一个字并将其转变成二进制,便于与GBK编码表进行比较if @charcate>=0XB0A1 and @charcate<=0XB0C4set @str1=@str1+'A'--说明此汉字的首字母为A,以下同上else if @charcate>=0XB0C5 and @charcate<=0XB2C0set @str1=@str1+'B'else if @charcate>=0XB2C1 and @charcate<=0XB4EDset @str1=@str1+'C'else if @charcate>=0XB4EE and @charcate<=0XB6E9set @str1=@str1+'D'else if @charcate>=0XB6EA and @charcate<=0XB7A1set @str1=@str1+'E'else if @charcate>=0XB7A2 and @charcate<=0XB8C0set @str1=@str1+'F'else if @charcate>=0XB8C1 and @charcate<=0XB9FDset @str1=@str1+'G'else if @charcate>=0XB9FE and @charcate<=0XBBF6set @str1=@str1+'H'else if @charcate>=0XBBF7 and @charcate<=0XBFA5set @str1=@str1+'J'else if @charcate>=0XBFA6 and @charcate<=0XC0ABset @str1=@str1+'K'else if @charcate>=0XC0AC and @charcate<=0XC2E7set @str1=@str1+'L'else if @charcate>=0XC2E8 and @charcate<=0XC4C2set @str1=@str1+'M'else if @charcate>=0XC4C3 and @charcate<=0XC5B5set @str1=@str1+'N'else if @charcate>=0XC5B6 and @charcate<=0XC5BDset @str1=@str1+'O'else if @charcate>=0XC5BE and @charcate<=0XC6D9set @str1=@str1+'P'else if @charcate>=0XC6DA and @charcate<=0XC8BAset @str1=@str1+'Q'else if @charcate>=0XC8BB and @charcate<=0XC8F5set @str1=@str1+'R'else if @charcate>=0XC8F6 and @charcate<=0XCBF9set @str1=@str1+'S'else if @charcate>=0XCBFA and @charcate<=0XCDD9set @str1=@str1+'T'else if @charcate>=0XCDDA and @charcate<=0XCEF3set @str1=@str1+'W'else if @charcate>=0XCEF4 and @charcate<=0XD1B8set @str1=@str1+'X'else if @charcate>=0XD1B9 and @charcate<=0XD4D0set @str1=@str1+'Y'else if @charcate>=0XD4D1 and @charcate<=0XD7F9set @str1=@str1+'Z'set @cyc=@cyc+1--取出输入汉字的下一个字endreturn @str1--返回输入汉字的首字母end
--测试数据
--select dbo.GetPY('从来就是这样酷,我酷,就是酷,看你能把我怎么样,哈哈')
------------------------------------------------------------------

转载于:https://www.cnblogs.com/liangdaye/p/3570650.html

sql 汉字转首字母拼音相关推荐

  1. 最强汉字得到首字母拼音java版

    网上有很多汉字得到首字母拼音的代码,基本都出自一种方式,通过对private static final char[] chartable = { '啊', * '芭', '擦', '搭', '蛾', ...

  2. 工具类:汉字得到首字母拼音

    1.取得给定汉字串的首字母串,即声母串,只支持GB2312字符集中的汉字,部分汉字不能转换: import java.io.UnsupportedEncodingException;public fi ...

  3. C# 根据汉字获取首字母拼音或全拼

    第一种方法.简单快速 若是求快,可以用下面这个方法,不需要什么库,直接写就完事 调用GetPYstring ,传入"世界和平",返回"SJHP" public ...

  4. sql 汉字按照首字母排序

    1.mysql 1)按照汉字的拼音排序 如果存储汉字的字段编码使用的是GBK字符集,因为GBK内码编码时本身就采用了拼音排序的方法(常用一级汉字3755个采用拼音排序,二级汉字就不是了,但考虑到人名等 ...

  5. KSO-sqlserver汉字取首字母拼音

    /创建取拼音首字母函数/ ALTER function [dbo].[fn_ChineseToSpell](@strChinese varchar(500)='') returns varchar(5 ...

  6. SQL语句——生成汉字首字母拼音

    sql脚本获取汉字首字母的2种方法: 1. create function GetPY(@str varchar(500)) returns varchar(500) as begin    decl ...

  7. oracle汉字转拼音(获得全拼/拼音首字母/拼音截取等)

    oracle汉字转拼音(获得全拼/拼音首字母/拼音截取等) oracle 字符集 GBK 没有问题 , UTF -8 需要修改一下 1.获得全拼 SELECT GETHZPY.GETHZFULLPY( ...

  8. JS实现获取汉字首字母拼音、全拼音及混拼音的方法

    本文实例讲述了JS实现获取汉字首字母拼音.全拼音及混拼音的方法.分享给大家供大家参考,具体如下: 这里需要用到一个js获取汉字拼音的插件,可点击此处本站下载. 运行效果如下: 完整示例代码: ? 1 ...

  9. 获取汉字的首字母和拼音

    /// /// 获取汉字的首字母和全拼 /// public class ChineseCode { protected string _CnTxt; protected string _EnTxt; ...

最新文章

  1. 数学推导+纯Python实现机器学习算法:逻辑回归
  2. Failed to install*.apk on device '': timeout
  3. [050] 微信公众平台开发入门视频教程已公布
  4. 9-Qt6 QString和QChar
  5. boost学习之boost::lock_guardT与boost::unique_lockT的区别
  6. 埋点测试-移动端/PC端
  7. 交叉熵损失函数原理详解,KL散度
  8. 电力企业信息化建设解决方案之计量生产分析系统
  9. 树莓派3B+编译OpenCV3.4.3详细步骤
  10. python装饰器@
  11. android用户界面是通过组件,[科技]Android 用户界面---定制组件(Custom Components)(一)...
  12. 论文毕业设计--基于javaweb框架的个人博客系统项目毕业设计论文.doc
  13. 【CGAL】提取中心线
  14. Mac 修改 hosts 文件
  15. MySQL的函数——聚合函数、数学函数、字符串函数、日期函数
  16. 多目标跟踪评价指标总结——MOTA、IDF1、HOTA等
  17. Fluent的porous jump边界条件
  18. nodejs01——安装及使用、服务端及客户端、commonjs规范、fs模块的使用(文件操作及目录操作)、stream、buffer、WebServer、端口、动态资源及静态资源、头信息、请求方式
  19. ps快捷键对应的英文字母缩写
  20. 会声会影2021软件下载如何制作视频剪辑制作教学

热门文章

  1. 进程死锁的危害、导致原因和解决方法
  2. WriteFile函数
  3. c语言不用switch做计算器,超级新手,用switch写了个计算器程序,求指导
  4. vscode更改插件路径_用好这7个 VS Code 插件,效率蹭蹭涨!
  5. 005_CSS通配符选择器
  6. internetreadfile读取数据长度为0_Datax3.0的安装和基本使用
  7. 计算机排版基础知识,计算机排版基础知识.pdf
  8. c# excel导出png_c#根据html模板导出excel
  9. Android开发中遇到的bug
  10. 09day ASM单实例安装部署,并在ASM上安装oracle数据库