MySQL实现汉字转拼音,赶快一起学起来( 三 )


declare v_pinyin VARCHAR(200);
#替换各种特殊符号
select replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
replace(replace(replace(replace(replace(replace(replace(replace(v_hanzi,
'A','A'),'B','B'),'C','C'),'D','D'),'E','E'),'F','F'),'G','G'),'H','H'),
'I','I'),'J','J'),'K','K'),'L','L'),'M','M'),'N','N'),'O','O'),'P','P'),
'Q','Q'),'R','R'),'S','S'),'T','T'),'U','U'),'V','V'),'W','W'),'X','X'),
'Y','Y'),'Z','Z'),'+',''),'-',''),'*',''),'/',''),
'[',''),']',''),'{',''),'}',''),'(',''),')',''),
'<',''),'>',''),'《',''),'》',''),'(',''),')',''),'"',''),
'“',''),'”',''),'.',''),' 。',''),'-',''),'-',''),'/',''),
'/',''),'',''),' ',''),'1','一'),'2','二'),'3','三'),
'4','四'),'5','五'),'6','六'),'7','七'),'8','八'),'9','九'),'0','零') R3
into V_NAME_TEMP
from dual;
if v_type = '1' then #简拼
set @V_NAME_TEMP=V_NAME_TEMP;
set @strResult=null;
call Prc_Get_Pym(@V_NAME_TEMP, @strResult);
elseif v_type = '2' then #尾全拼
#判断结尾字符是否是中文
select ltrim(rtrim(substr(V_NAME_TEMP, char_length(V_NAME_TEMP), char_length(V_NAME_TEMP))))
into v_subb
from dual;
if v_subb is null then #如果不是中文则直接生成开口码
set @V_NAME_TEMP=V_NAME_TEMP;
set @strResult=null;
call Prc_Get_Pym(@V_NAME_TEMP, @strResult);
else
select substr(V_NAME_TEMP, 1, char_length(V_NAME_TEMP)-1) into strHanzi from dual;
set @strHanzi=strHanzi;
set @strTemp1=null;
call Prc_Get_Pym(@strHanzi, @strTemp1);
select substr(V_NAME_TEMP, char_length(V_NAME_TEMP), char_length(V_NAME_TEMP)) into strHanzi from dual;
set @strHanzi=strHanzi;
set @strTemp=null;
call Sp_Pinyin(@strHanzi, @strTemp);
select substr(@strTemp, 1, char_length(@strTemp) - 1) into @strResult from dual;
select concat_ws('',@strTemp1,@strResult) into @strResult from dual;
end if;
elseif v_type = '3' then #首全拼
#判断开头字符是否是中文
select ltrim(rtrim(substr(V_NAME_TEMP, 1, 1))) into v_subb from dual;
if v_subb is null then #如果不是中文则直接生成开口码
set @V_NAME_TEMP=V_NAME_TEMP;
set @strResult=null;
call Prc_Get_Pym(@V_NAME_TEMP, @strResult);
else
select substr(V_NAME_TEMP, 2, char_length(V_NAME_TEMP)) into strHanzi from dual;
set @strHanzi=strHanzi;
set @strResult=null;
call Prc_Get_Pym(@strHanzi, @strResult);
select substr(V_NAME_TEMP, 1, 1) into strHanzi from dual;
set @strHanzi=strHanzi;
set @strTemp=null;
call Sp_Pinyin(@strHanzi, @strTemp);
select concat_ws('',substr(@strTemp, 1, char_length(@strTemp) - 1),@strResult) into @strResult from dual;
end if;
end if;
set v_pinyin=UPPER(@strResult);
return v_pinyin;
end;
$$
delimiter ;
4. 使用方法/案例

MySQL实现汉字转拼音,赶快一起学起来

文章插图
 




推荐阅读