从全拼音中得到汉字拼音

本文介绍两种在SQL中实现汉字到拼音转换的方法:一种是通过定义一个存储过程来逐字符匹配并转换;另一种是从全拼码表文件中批量导入拼音数据,并展示如何读取和处理这些数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 --(1) JJ的

create function [dbo].[funcGetPY](@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

--Z老大

/*--从全拼音中得到汉字拼音 
  
  首先,用输入法生成器(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     --如果是获得单字的读音 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值