一个用于检索拼音的SQL函数
2007-04-12 15:41
148 查看
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'
相关文章推荐
- 今天写了一个KMP匹配算法,写好后发现用于拼音匹配时不合适,暂存一下吧
- iOS开发:一个高仿美团的团购ipad客户端的设计和实现(功能:根据拼音进行检索并展示数据,离线缓存团购数据,浏览记录与收藏记录的批量删除等)
- 一个sql函数,把汉字首字母转换成拼音,
- 62.多线程多文件检索,每个线程检索一个文件,用于内存不够的情况下
- 一个用VC生成DLL并用于其它工具的问题
- 一个用于图片上传的工具类(原)
- 此地址使用了一个通常用于网络浏览以外目的的端口。出于安全原因,Firefox 取消了该请求。
- Druid:一个用于大数据实时处理的开源分布式系统之怎么用
- Selenium-一个用于Web应用程序测试的工具
- 在Delphi中用拼音首字符序列来实现检索功能
- [C++ 平时小练习] 写一个函数gene 用于输出正整数的全部因子,例如当k=126时,如下格式输出126=2*3*3*7
- 一个发包小程序 一种用于自动化测试的脚本语言
- (转载)一个用于Gnome桌面的下拉式终端: Guake 0.7.0 发布
- Solr之拼音检索。
- Spark DataFrame----一个用于大规模数据科学的API
- 使用select2插件并添加拼音首字母检索
- SQL Server中如何把一个任意汉字转换为该汉字拼音第一个字母
- .Net里一个用于驱动摄像头的类
- oracle 用到的一个比较复杂的sql函数
- .Net里一个用于驱动摄像头的类