--写个处理函数
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

解决方案 »

  1.   

    --查询的时候这样调用
    select * from 表 where dbo.f_GetPy(name)=dbo.f_GetPy(N'黎明')
      

  2.   

    在其他的开发环境中实现也可以,比如vb,delphi,vc都行!
      

  3.   

    zjcxc(邹建)大哥,有个问题,这样的话我输入“乐名”,把“黎明“和“李名”以及其他的拼音开头带"L"的都查了出来
      

  4.   

    --参考:/*--从全拼音中得到汉字拼音 首先,用输入法生成器(Imegen.exe)的逆转换功能
    将全拼的码表文件 WINPY.MB 转换成文本文件 c:\winpy.txt
    然后用下面的语句导入到数据库中
    下面只是显示了读取并显示的过程,并没有存储到具体的表中

    读取语句中的:
    with(datafiletype='widechar')  的作用是处理unicode数据
    我是用win2000测试的,转换的文本文件编码是unicode
    如果是编码是ansi,则不要这句 查看文本文件编码,可以用记事本打开文本文件,另存为,就可以看到当前编码
    --*/--创建临时表
    create table #t(a varchar(500))--导入数据
    bulk insert #t from 'c:\winpy.txt'
    with(datafiletype='widechar')--删除表头
    set rowcount 12
    delete from #t
    set rowcount 0--分拆处理
    select 汉字=left(a,patindex('%[a-z]%',a)-1)
    ,拼音=stuff(a,1,patindex('%[a-z]%',a)-1,'')
    from #t
    --where patindex('%[a-z]%',a)=2  --如果是获得单字的读音--删除测试
    drop table #t
      

  5.   

    --使用拼音表实现同音字查询--测试数据
    create table 拼音字典表(汉字 nchar(1),拼音 varchar(10))
    insert 拼音字典表 select '长','chang'
    insert 拼音字典表 select '长','zhang'
    insert 拼音字典表 select '城','cheng'
    insert 拼音字典表 select '章','zhang'
    insert 拼音字典表 select '源','yuan'
    insert 拼音字典表 select '缘','yuan'
    insert 拼音字典表 select '风','feng'
    insert 拼音字典表 select '凤','feng'
    insert 拼音字典表 select '丰','feng'create table 数据表(单词 varchar(100))
    insert 数据表 select '源丰'
    insert 数据表 select '长风'
    insert 数据表 select '缘凤'
    go--写个查询处理的自定义函数,返回指定单词的所有同音词
    create function f_qry(
    @word Nvarchar(1000) --要查询的汉字
    )returns @r table(word varchar(1000))
    as
    begin
    if isnull(@word,'') is null return declare @t table(word varchar(1000),level int)
    declare @l int
    set @l=1

    insert @t select a.汉字,@l
    from 拼音字典表 a,拼音字典表 b
    where a.拼音=b.拼音
    and b.汉字=left(@word,1)

    while @@rowcount>0
    begin
    select @l=@l+1
    insert @t select r.word+a.汉字,@l
    from @t r,拼音字典表 a,拼音字典表 b
    where a.拼音=b.拼音
    and r.level=@l-1
    and b.汉字=substring(@word,@l,1)
    end
    insert @r select word from @t where level=@l-1
    return
    end
    go--调用上面的函数实现查询
    select a.* from 数据表 a,f_qry('源风') b where a.单词=b.word
    go--删除测试
    drop table 拼音字典表,数据表
    drop function f_qry/*--测试结果单词               
    -------------------
    源丰
    缘凤(所影响的行数为 2 行)
    --*/