sql获取汉字的拼音首字母

简介: /*创建取拼音首字母函数*/ create function [dbo].[fn_ChineseToSpell](@strChinese varchar(500)='') returns varchar(500) as begin /*函数实现开始*/ declar...
/*创建取拼音首字母函数*/ 
create function [dbo].[fn_ChineseToSpell](@strChinese varchar(500)='') 
returns varchar(500) 
as 
begin /*函数实现开始*/ 
     declare @strLen int,@return varchar(500),@i int 
     declare @n int,@c char(1),@chn nchar(1)  
     select @strLen=len(@strChinese),@return='',@i=0 
     while @i<@strLen 
     begin /*while循环开始*/
             select @i=@i+1,@n=63,@chn=substring(@strChinese,@i,1) 
             if @chn>'z'/*原理:“字符串排序以及ASCII码表”*/                
                 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 '' /*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 '' union all select @chn) as a  order by chn COLLATE Chinese_PRC_CI_AS ) as b  
             else
                 set @c=@chn
             set @return=@return+@c  
     end /*while循环结束*/  
     return(@return)  
end /*函数实现结束*/

使用方式:
select dbo.[fn_ChineseToSpell]('吴缤')

相关文章
|
22天前
|
SQL 存储 Python
Microsoft SQL Server 编写汉字转拼音函数
Microsoft SQL Server 编写汉字转拼音函数
|
SQL Go 数据安全/隐私保护
|
SQL Web App开发 关系型数据库
|
SQL
SQL 将URL编码转汉字!
原文: SQL 将URL编码转汉字! -- ============================================= -- 作 者: ruijc -- 描 述: 将Url编码转明文字符串 -- ============...
1034 0
|
SQL
sql 提取数字、字母、汉字
代码 --提取数字IF OBJECT_ID('DBO.GET_NUMBER2') IS NOT NULLDROP FUNCTION DBO.GET_NUMBER2GOCREATE FUNCTION DBO.
732 0
|
5天前
|
SQL 人工智能 算法
【SQL server】玩转SQL server数据库:第二章 关系数据库
【SQL server】玩转SQL server数据库:第二章 关系数据库
40 10
|
1月前
|
SQL 数据库 数据安全/隐私保护
Sql Server数据库Sa密码如何修改
Sql Server数据库Sa密码如何修改
|
2月前
|
SQL 算法 数据库
【数据库SQL server】关系数据库标准语言SQL之数据查询
【数据库SQL server】关系数据库标准语言SQL之数据查询
95 0
|
15天前
|
SQL
启动mysq异常The server quit without updating PID file [FAILED]sql/data/***.pi根本解决方案
启动mysq异常The server quit without updating PID file [FAILED]sql/data/***.pi根本解决方案
15 0
|
5天前
|
SQL 算法 数据库
【SQL server】玩转SQL server数据库:第三章 关系数据库标准语言SQL(二)数据查询
【SQL server】玩转SQL server数据库:第三章 关系数据库标准语言SQL(二)数据查询
55 6