• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase
您的位置:首页 > 数据库 >Mysql > sql存储过程获取汉字拼音头字母函数

sql存储过程获取汉字拼音头字母函数

作者:匿名 字体:[增加 减小] 来源:互联网 时间:2018-12-05

匿名通过本文主要向大家介绍了存储过程,汉字拼音,头字母等相关知识,希望本文的分享对您有所帮助

sql存储过程获取汉字拼音头字母函数,需要的朋友可以参考下。

代码如下:
--函数
CREATE function fn_GetPy(@str nvarchar(4000))
returns nvarchar(4000)
--WITH ENCRYPTION
as
begin
declare @intLenint
declare @strRetnvarchar(4000)
declare @temp nvarchar(100)
set @intLen = len(@str)
set @strRet = ''
while @intLen > 0
begin
set @temp = ''
select @temp = case
when substring(@str,@intLen,1) >= '帀' then 'Z'
when substring(@str,@intLen,1) >= '丫' then 'Y'
when substring(@str,@intLen,1) >= '夕' then 'X'
when substring(@str,@intLen,1) >= '屲' then 'W'
when substring(@str,@intLen,1) >= '他' then 'T'
when substring(@str,@intLen,1) >= '仨' then 'S'
when substring(@str,@intLen,1) >= '呥' then 'R'
when substring(@str,@intLen,1) >= '七' then 'Q'
when substring(@str,@intLen,1) >= '妑' then 'P'
when substring(@str,@intLen,1) >= '噢' then 'O'
when substring(@str,@intLen,1) >= '拏' then 'N'
when substring(@str,@intLen,1) >= '嘸' then 'M'
when substring(@str,@intLen,1) >= '垃' then 'L'
when substring(@str,@intLen,1) >= '咔' then 'K'
when substring(@str,@intLen,1) >= '丌' then 'J'
when substring(@str,@intLen,1) >= '铪' then 'H'
when substring(@str,@intLen,1) >= '旮' then 'G'
when substring(@str,@intLen,1) >= '发' then 'F'
when substring(@str,@intLen,1) >= '妸' then 'E'
when substring(@str,@intLen,1) >= '咑' then 'D'
when substring(@str,@intLen,1) >= '嚓' then 'C'
when substring(@str,@intLen,1) >= '八' then 'B'
when substring(@str,@intLen,1) >= '吖' then 'A'
else rtrim(ltrim(substring(@str,@intLen,1)))
end
--对于汉字特殊字符,不生成拼音码
if (ascii(@temp)>127) set @temp = ''
--对于英文中小括号,不生成拼音码
if @temp = '(' or @temp = ')' set @temp = ''
select @strRet = @temp + @strRet
set @intLen = @intLen - 1
end
return lower(@strRet)
end
go
--调用
select dbo.fn_getpy('张三')
--返回:zs
答!: 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
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • mysql 精简过程(删除一些文件)
  • mysql存储过程 在动态SQL内获取返回值的方法详解
  • 深入mysql存储过程中表名使用参数传入的详解
  • 基于mysql多实例安装的深入解析
  • 深入mysql创建自定义函数与存储过程的详解
  • 基于Php mysql存储过程的详解
  • Mysql DNS反向解析导致连接超时过程分析(skip-name-resolve)
  • 一次非法关机导致mysql数据表损坏的实例解决
  • Mysql的游标的定义使用及关闭深入分析
  • mysql存储过程 游标 循环使用介绍

相关文章

  • 2018-12-05Debian使用dpkg安装MySQL的方法
  • 2018-12-05sql 版本详解 让你认识跟sql2000的区别
  • 2017-05-11mysql insert的几点操作(DELAYED,IGNORE,ON DUPLICATE KEY UPDATE )
  • 2018-12-05cmd 命令行模式操作数据库( 表,字段, 数据的增删改查)
  • 2018-12-05sql基本函数大全
  • 2018-12-05Oracle中利用plsql developer导出导入存储过程
  • 2018-12-05MySQL基础教程11 — 函数之Cast函数和操作符
  • 2018-12-05CPU资源和可用内存大小对数据库性能有何影响?
  • 2017-05-11mysql安全启动脚本mysqld_safe详细介绍
  • 2018-12-05sql server:alter database name的问题

文章分类

  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase

最近更新的内容

    • 一列保存多个ID(将多个用逗号隔开的ID转换成用逗号隔开的名称)
    • MySQL navicate功能详解
    • SQL server 管理事务和数据库介绍
    • mysql 5.7.11 winx64安装配置教程_MySQL
    • 关于MySQL Query Cache的一些交流心得
    • 【MySQL 11】注释
    • SQLServer2005与SQLServer2008数据库同步图文教程
    • 如何优化性能?MySQL实现批量插入以优化性能的实例详解
    • mysql SELECT语句去除某个字段的重复信息
    • 在win7上安装oracle 10g配置文件更改

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有