大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
CREATE OR REPLACE Function F_GetHzPy(V_HZ Varchar2,V_XS Varchar2 Default 'U',V_FG Varchar2 Default ' ') Return Varchar2 As V_PY Varchar2(100) Default NULL;
创新互联自2013年创立以来,是专业互联网技术服务公司,拥有项目成都做网站、成都网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元雨花做网站,已为上家服务,为雨花各地企业和个人服务,联系电话:028-86922220
L_HZ Varchar2(8);
L_PY Varchar2(24);
I Number;
Cursor CUR_PY Is Select C_PY From XT_HZPY Where C_HZ = L_HZ AND ROWNUM2;
Cursor CUR_PT Is Select SubstrB(C_PY,1,1) From XT_HZPY Where C_HZ = L_HZ AND ROWNUM2;
--获取汉字拼音函数F_GetHzPy('汉字串','返回大小写,默认为大写,传U为大写,其他字符或D为小写','返回拼音值的每个汉字拼音的间隔符号,默认为空格')
--例如:F_GetHzPy('中华民族','D','/') 返回值为'zhong/hua/minzu'
--例如:F_GetHzPy('中华民族') 返回值为'ZHONG HUA MINZU'
--拼音头例如:F_GetHzPy('中华民族','D','PT') 返回值为'zhmz'
Begin
I:=1;
While I= Length(V_HZ) Loop
L_HZ := Substr(V_HZ,I,1);
L_PY:=NULL;
If upper(V_FG)'PT' Then
OPEN CUR_PY;
FETCH CUR_PY INTO L_PY;
CLOSE CUR_PY;
Else
OPEN CUR_PT;
FETCH CUR_PT INTO L_PY;
CLOSE CUR_PT;
End If;
L_PY:=Replace(L_PY,' ','');
If Nvl(L_PY,'NULL')='NULL' Then
L_PY:=L_HZ;
End If;
If V_XS='U' Then
L_PY:=upper(L_PY);
End If;
If I=Length(V_HZ) Then
V_PY:=V_PY||L_PY;
Else
If V_PY Is NULL Then
V_PY:=L_PY;
Else
If upper(V_FG)'PT' Then
V_PY:=V_PY||V_FG||L_PY;
Else
V_PY:=V_PY||L_PY;
End If;
End If;
End If;
I:=I+1;
End Loop;
V_PY:=Trim(V_PY);
Return V_PY;
End;
/
首先你得有 对应的汉字拼音表
然后才能、写个函数 做转换
楼主您好
没有特别好的方法
如果数据特别巨大的话,建议写程序转换
拿java为例,即使高级语言,用pingyin4j读出来,多音字返回数组电脑是没办法识别的。我们只能暂时先让它返回第一个音,比如长返回["chang","zhang"],只能默认chang音,“长大”也就错了。
比如“万俟卨”电脑是肯定读不对的。
CREATE OR REPLACE FUNCTION F_PINYIN(P_NAME IN VARCHAR2) RETURN VARCHAR2 AS
V_COMPARE VARCHAR2(100);
V_RETURN VARCHAR2(4000);
FUNCTION F_NLSSORT(P_WORD IN VARCHAR2) RETURN VARCHAR2 AS
BEGIN
RETURN NLSSORT(P_WORD, 'NLS_SORT=SCHINESE_PINYIN_M');
END;
BEGIN
FOR I IN 1..LENGTH(P_NAME) LOOP
V_COMPARE := F_NLSSORT(SUBSTR(P_NAME, I, 1));
IF V_COMPARE = F_NLSSORT(' 吖 ') AND V_COMPARE = F_NLSSORT('骜 ') THEN
V_RETURN := V_RETURN || 'A';
ELSIF V_COMPARE = F_NLSSORT('八 ') AND V_COMPARE = F_NLSSORT('簿 ') THEN
V_RETURN := V_RETURN || 'B';
ELSIF V_COMPARE = F_NLSSORT('嚓 ') AND V_COMPARE = F_NLSSORT('错 ') THEN
V_RETURN := V_RETURN || 'C';
ELSIF V_COMPARE = F_NLSSORT('咑 ') AND V_COMPARE = F_NLSSORT('鵽 ') THEN
V_RETURN := V_RETURN || 'D';
ELSIF V_COMPARE = F_NLSSORT('妸 ') AND V_COMPARE = F_NLSSORT('樲 ') THEN
V_RETURN := V_RETURN || 'E';
ELSIF V_COMPARE = F_NLSSORT('发 ') AND V_COMPARE = F_NLSSORT('猤 ') THEN
V_RETURN := V_RETURN || 'F';
ELSIF V_COMPARE = F_NLSSORT('旮 ') AND V_COMPARE = F_NLSSORT('腂 ') THEN
V_RETURN := V_RETURN || 'G';
ELSIF V_COMPARE = F_NLSSORT('妎 ') AND V_COMPARE = F_NLSSORT('夻 ') THEN
V_RETURN := V_RETURN || 'H';
ELSIF V_COMPARE = F_NLSSORT('丌 ') AND V_COMPARE = F_NLSSORT('攈 ') THEN
V_RETURN := V_RETURN || 'J';
ELSIF V_COMPARE = F_NLSSORT('咔 ') AND V_COMPARE = F_NLSSORT('穒 ') THEN
V_RETURN := V_RETURN || 'K';
ELSIF V_COMPARE = F_NLSSORT('垃 ') AND V_COMPARE = F_NLSSORT('擽 ') THEN
V_RETURN := V_RETURN || 'L';
ELSIF V_COMPARE = F_NLSSORT('呒 ') AND V_COMPARE = F_NLSSORT('椧 ') THEN
V_RETURN := V_RETURN || 'M';
ELSIF V_COMPARE = F_NLSSORT('拏 ') AND V_COMPARE = F_NLSSORT('疟 ') THEN
V_RETURN := V_RETURN || 'N';
ELSIF V_COMPARE = F_NLSSORT('筽 ') AND V_COMPARE = F_NLSSORT('沤 ') THEN
V_RETURN := V_RETURN || 'O';
ELSIF V_COMPARE = F_NLSSORT('妑 ') AND V_COMPARE = F_NLSSORT('曝 ') THEN
V_RETURN := V_RETURN || 'P';
ELSIF V_COMPARE = F_NLSSORT('七 ') AND V_COMPARE = F_NLSSORT('裠 ') THEN
V_RETURN := V_RETURN || 'Q';
ELSIF V_COMPARE = F_NLSSORT('亽 ') AND V_COMPARE = F_NLSSORT('鶸 ') THEN
V_RETURN := V_RETURN || 'R';
ELSIF V_COMPARE = F_NLSSORT('仨 ') AND V_COMPARE = F_NLSSORT('蜶 ') THEN
V_RETURN := V_RETURN || 'S';
ELSIF V_COMPARE = F_NLSSORT('侤 ') AND V_COMPARE = F_NLSSORT('箨 ') THEN
V_RETURN := V_RETURN || 'T';
ELSIF V_COMPARE = F_NLSSORT('屲 ') AND V_COMPARE = F_NLSSORT('鹜 ') THEN
V_RETURN := V_RETURN || 'W';
ELSIF V_COMPARE = F_NLSSORT('夕 ') AND V_COMPARE = F_NLSSORT('鑂 ') THEN
V_RETURN := V_RETURN || 'X';
ELSIF V_COMPARE = F_NLSSORT('丫 ') AND V_COMPARE = F_NLSSORT('韵 ') THEN
V_RETURN := V_RETURN || 'Y';
ELSIF V_COMPARE = F_NLSSORT('帀 ') AND V_COMPARE = F_NLSSORT('咗 ') THEN
V_RETURN := V_RETURN || 'Z';
ELSE V_RETURN := V_RETURN ||SUBSTR(P_NAME, I, 1);
END IF;
END LOOP;
RETURN V_RETURN;
END;
eg: select f_pinyin('我爱中华!') from dual
WAZH!
这是转换成拼音第一个字母的
create or replace function Calcu_pydm(
as_InputString IN VARCHAR --输入字符串
)
RETURN VARCHAR2
IS
ll_pos NUMBER ;
tmp VARCHAR2(4) ;
ls_ReturnStr VARCHAR2(8000);
begin
ll_pos :=1;
ls_ReturnStr := '';
WHILE ll_pos = LENGTH(as_InputString)
LOOP
tmp := SubStr(as_InputString,ll_pos,1);
if ASCII(tmp) 128 then
if tmp= '匝' then
ls_ReturnStr := ls_ReturnStr || 'Z';
end if;
if tmp= '丫' and tmp '匝' then
ls_ReturnStr := ls_ReturnStr || 'Y';
end if;
if tmp= '夕' and tmp '丫' then
ls_ReturnStr := ls_ReturnStr || 'X';
end if;
if tmp= '哇' and tmp '夕' then
ls_ReturnStr := ls_ReturnStr || 'W';
end if;
if tmp= '他' and tmp '哇' then
ls_ReturnStr := ls_ReturnStr || 'T';
end if;
if tmp= '撒' and tmp '他' then
ls_ReturnStr := ls_ReturnStr || 'S';
end if;
if tmp= '然' and tmp '撒' then
ls_ReturnStr := ls_ReturnStr || 'R';
end if;
if tmp= '七' and tmp '然' then
ls_ReturnStr := ls_ReturnStr || 'Q';
end if;
if tmp= '趴' and tmp '七' then
ls_ReturnStr := ls_ReturnStr || 'P';
end if;
if tmp= '哦' and tmp '趴' then
ls_ReturnStr := ls_ReturnStr || 'O';
end if;
if tmp= '拿' and tmp '哦' then
ls_ReturnStr := ls_ReturnStr || 'N';
end if;
if tmp= '妈' and tmp '拿' then
ls_ReturnStr := ls_ReturnStr || 'M';
end if;
if tmp= '廓' and tmp '妈' then
ls_ReturnStr := ls_ReturnStr || 'L';
end if;
if tmp= '咖' and tmp '廓' then
ls_ReturnStr := ls_ReturnStr || 'K';
end if;
if tmp= '讥' and tmp '咖' then
ls_ReturnStr := ls_ReturnStr || 'J';
end if;
if tmp= '哈' and tmp '讥' then
ls_ReturnStr := ls_ReturnStr || 'H';
end if;
if tmp= '嘎' and tmp '哈' then
ls_ReturnStr := ls_ReturnStr || 'G';
end if;
if tmp= '发' and tmp '嘎' then
ls_ReturnStr := ls_ReturnStr || 'F';
end if;
if tmp= '讹' and tmp '发' then
ls_ReturnStr := ls_ReturnStr || 'E';
end if;
if tmp= '搭' and tmp '讹' then
ls_ReturnStr := ls_ReturnStr || 'D';
end if;
if tmp= '擦' and tmp '搭' then
ls_ReturnStr := ls_ReturnStr || 'C';
end if;
if tmp= '八' and tmp '擦' then
ls_ReturnStr := ls_ReturnStr || 'B';
end if;
if tmp= '啊' and tmp '八' then
ls_ReturnStr := ls_ReturnStr || 'A';
end if;
if tmp '啊' then
ls_ReturnStr := ls_ReturnStr || SubStr(as_InputString,ll_pos,1);
end if;
else
ls_ReturnStr :=ls_ReturnStr || SubStr(as_InputString,ll_pos,1);
end if;
ll_pos := ll_pos + 1 ;
end loop;
ls_ReturnStr := lower(rtrim(ltrim(ls_ReturnStr)));
return ls_ReturnStr;
end ;