想将中文转化问拼音,出现问题了,帮忙看看
需要将字段name由中文转化问拼音,大家帮忙看看,有问题了,
declare @hanzi nvarchar(500),
@pinyin nvarchar(20),
@name nvarchar(500),
@nameen nvarchar(1000),
@i int,
@conseq int
set @i=1
declare topinyin cursor for select name,conseq ,nameen from conmas where conseq <1000 order by conseq/*name为中文字段,conseq为主键,int,nameen为name转化为拼音的字段,默认值为 ' '*/
open topinyin
fetch next from topinyin into @name,@conseq,@nameen
print @conseq
while @@FETCH_STATUS = 0
Begin
while @i <=len(@name)
begin
select @hanzi= substring(@name,@i,1)
select @pinyin= 拼音 from 汉字拼音表 where patindex( '% '+@hanzi+ '% ',汉字) <> 0
update conmas set nameen=nameen+ ' '+@pinyin where conseq=@conseq
select @i=@i+1
end
fetch next from topinyin into @name,@conseq,@nameen
return
End
CLOSE topinyin
deallocate topinyin/*
汉字拼音表格式为
拼音 汉字
a <所有发音问a的汉字>
ai <所有发音问ai的汉字> */
[解决办法]
while @@FETCH_STATUS = 0
Begin
set @i=1
while @i <=len(@name)
begin
select @hanzi= substring(@name,@i,1)
select @pinyin= 拼音 from 汉字拼音表 where patindex( '% '+@hanzi+ '% ',汉字) <> 0
update conmas set nameen=nameen+ ' '+@pinyin where conseq=@conseq
select @i=@i+1
end
fetch next from topinyin into @name,@conseq,@nameen
return---去掉
End
[解决办法]
while @@FETCH_STATUS = 0
Begin
set @i=1
while @i <=len(@name)
begin
select @hanzi= substring(@name,@i,1)
select @pinyin= 拼音 from 汉字拼音表 where patindex( '% '+@hanzi+ '% ',汉字) <> 0
update conmas set nameen=nameen+ ' '+@pinyin where conseq=@conseq
select @i=@i+1
end
fetch next from topinyin into @name,@conseq,@nameen
return---去掉
End 这个我试过也不行!!
[解决办法]
CREATE TABLE [dbo].[conmas]([conSeq] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL,
[NameEN] [nvarchar](50) NULL CONSTRAINT [DF_conmas_NameEN] DEFAULT ( ' ')
CONSTRAINT [PK_conmas] PRIMARY KEY CLUSTERED ([conSeq] ASC))
insert conmas(name)values( '啊边 ')
insert conmas(name)values( '被边 ')
CREATE TABLE [dbo].[汉字拼音表](
[拼音] [nvarchar](255) NULL,
[汉字] [nvarchar](500) NULL)
insert [汉字拼音表]([拼音] ,[汉字] )values( 'a ', '啊阿呵 ')
insert [汉字拼音表]([拼音] ,[汉字] )values( 'bei ', '被北倍杯 ')
insert [汉字拼音表]([拼音] ,[汉字] )values( 'bian ', '边变便遍 ')
declare @hanzi nvarchar(500),
@pinyin nvarchar(20),
@name nvarchar(500),
@nameen nvarchar(1000),
@i int,
@conseq int
declare topinyin cursor for select name,conseq ,nameen from conmas where conseq <1000 order by conseq
open topinyin
fetch next from topinyin into @name,@conseq,@nameen
print @conseq
while @@FETCH_STATUS = 0
Begin
set @i=1
while @i <=len(@name)
begin
select @hanzi= substring(@name,@i,1)
select @pinyin= 拼音 from 汉字拼音表 where patindex( '% '+@hanzi+ '% ',汉字) <> 0
update conmas set nameen=nameen+ ' '+@pinyin where conseq=@conseq
select @i=@i+1
end
fetch next from topinyin into @name,@conseq,@nameen
End
CLOSE topinyin
deallocate topinyin
select * from conmas
--result
/*
conSeq Name NameEN
----------- ------------- ----------------
1 啊边 a bian
2 被边 bei bian
(所影响的行数为 2 行)
*/