一个sql server中用到的函数,用来取拼音
2005-01-12 08:55
267 查看
create function f_GetPy(@str nvarchar(4000))
returns nvarchar(4000)
as
begin
declare @strlen int,@re nvarchar(4000)
declare @t table(chr nchar(1) collate Chinese_PRC_CI_AS,letter nchar(1))
insert into @t(chr,letter)
select '吖','A' union all select '八','B' union all
select '嚓','C' union all select '咑','D' union all
select '妸','E' union all select '发','F' union all
select '旮','G' union all select '铪','H' union all
select '丌','J' union all select '咔','K' union all
select '垃','L' union all select '嘸','M' union all
select '拏','N' union all select '噢','O' union all
select '妑','P' union all select '七','Q' union all
select '呥','R' union all select '仨','S' union all
select '他','T' union all select '屲','W' union all
select '夕','X' union all select '丫','Y' union all
select '帀','Z'
select @strlen=len(@str),@re=''
while @strlen>0
begin
select top 1 @re=letter+@re,@strlen=@strlen-1
from @t a where chr<=substring(@str,@strlen,1)
order by chr desc
if @@rowcount=0
select @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1
end
return(@re)
end
go
--调用
select * from alls where dbo.f_GetPy(name)='cyml'
returns nvarchar(4000)
as
begin
declare @strlen int,@re nvarchar(4000)
declare @t table(chr nchar(1) collate Chinese_PRC_CI_AS,letter nchar(1))
insert into @t(chr,letter)
select '吖','A' union all select '八','B' union all
select '嚓','C' union all select '咑','D' union all
select '妸','E' union all select '发','F' union all
select '旮','G' union all select '铪','H' union all
select '丌','J' union all select '咔','K' union all
select '垃','L' union all select '嘸','M' union all
select '拏','N' union all select '噢','O' union all
select '妑','P' union all select '七','Q' union all
select '呥','R' union all select '仨','S' union all
select '他','T' union all select '屲','W' union all
select '夕','X' union all select '丫','Y' union all
select '帀','Z'
select @strlen=len(@str),@re=''
while @strlen>0
begin
select top 1 @re=letter+@re,@strlen=@strlen-1
from @t a where chr<=substring(@str,@strlen,1)
order by chr desc
if @@rowcount=0
select @re=substring(@str,@strlen,1)+@re,@strlen=@strlen-1
end
return(@re)
end
go
--调用
select * from alls where dbo.f_GetPy(name)='cyml'
相关文章推荐
- sql server中用到的函数,用来取拼音
- 一个sqlserver中用到的函数,用来取拼音
- 请实现一个函数用来匹配包括'.'和'*'的正则表达式。模式中的字符'.'表示任意一个字符,而'*'表示它前面的字符可以出现任意次(包含0次)。 在本题中,匹配是指字符串的所有字符匹配整个模式。
- 《牛客网剑指offer54题》请实现一个函数用来找出字符流中第一个只出现一次的字符
- 我在编程里用到的函数,归在一个类中(未完)
- C#、Oracle、Sql server中拼音查询的函数
- SQL Server中取汉字拼音的函数
- [剑指Offer-字符串]请实现一个函数用来找出字符流中第一个只出现一次的字符。
- 编写一个函数,用来删除字符串中的空格
- 自己用到的一个字符串替换函数
- sql server 一个简单的函数
- 两头堵模型(用来去除有一个字符串开头或结尾含有n个空格(” abcdefgdddd ”),欲去掉前后空格,返回一个新字符串。),工程开发经常需要用到的
- 能把汉字转化为拼音的一个函数
- 只有当一个类被用来作为基类的时候,才把析构函数写成虚函数.
- 写一个函数,用来把一个字符串用指定的字符作为分隔符分割成若干个子串输出 | 写一个函数,用来返回一个字符串中重复出现的最长字串的长度及其开始地址
- 能把汉字转化为拼音的一个函数
- 一个很不错的汉字转化为拼音的函数 php
- 一个返回汉字首字母的函数SQL Server
- 请实现一个函数用来匹配包括'.'和'*'的正则表达式。模式中的字符'.'表示任意一个字符,而'*'表示它前面的字符可以出现任意次(包含0次)。 在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字
- 实现一个函数用来找出字符流中第一个只出现一次的字符。