根据汉字声母,在表中找相关记录
来源:互联网 发布:1号店下单软件 编辑:程序博客网 时间:2024/06/02 22:13
根据汉字声母,要在表中找相关记录,怎么实现?比如输入"zgyh",就能找到所有“中国银行”的记录。
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_GetPy]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_GetPy]
GO
--创建取拼音函数
create function f_GetPy(@Str nvarchar(400))
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 @t 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 dbo.f_GetPy('东莞市') as 东莞市,dbo.f_GetPy('ab中c国人') as 中国人
--以后查询的时候,就可以调用上面的函数来实现汉字模糊查询
select * from 表 where dbo.f_getpy(字段)='zgyh'
--你可以这样建表
create table 表(id int identity(int,1,1),汉字字段 nvarchar(50),拼音字段 nvarchar(50))
go
--在新增/修改数据的时候,即时更新拼音字段
create trigger tr_py on 表
for update,insert
as
if update(汉字字段)
update 表 set 拼音字段=dbo.f_getpy(汉字字段)
from 表 a join inserted b on a.id=b.id
go
--这样,以后查询的时候就不用去调函数,直接查询即可
select * from 表 where 拼音字段='zgyh'
- 根据汉字声母,在表中找相关记录
- 根据汉字声母,要在表中找相关记录,怎么实现?比如输入"zgyh",就能找到所有“中国银行”的记录。
- 根据汉字声母,在表中找相关记录。比如输入"zgyh",就能找到所有“中国银行”的记录。
- 根据汉字声母,在表中找相关记录。比如输入"zgyh",就能找到所有“中国银行”的记录zz
- 根据汉字声母,在表中找相关记录。比如输入"zgyh",就能找到所有“中国银行”的记录。
- 在Sql server 如何得到汉字的声母
- 汉字拼音声母计算类
- asp.net获取汉字声母
- excel中汉字转成声母
- 汉字拼音声母计算类
- 汉字拼音声母计算类
- Delphi中实现汉字拼音声母查询
- Sql server 如何得到汉字的声母
- C# 获取汉字字串的拼音声母
- 汉字转换拼音缩写之声母
- 根据中文字符串查询拼音声母
- 返回给定汉字串的首字母串,即声母串
- sqlServer 中 获取汉字字串的拼音声母
- 红客所知的十五大问题
- 壳学习一:PECompact 2.x 加壳脱壳
- Java对各种文件的操作详解
- 这Blog真糟糕
- http://www.skycn.com/soft/20700.html#download
- 根据汉字声母,在表中找相关记录
- 水晶五笔下载地址(非技术)
- 简直绝了:周星驰与赵本山的对话
- 不能给你幸福
- Half-Life 2 - Lost Coast
- 如果你的心灵是一棵树的种子,你早晚有一天会长成参天大树……
- 项目刷新失败,无法从服务器中检索文件夹信息的解决办法
- 待完成的工作。
- 如何给VSFTP增加用户,只能访问指定目录