oracle 8i 中文转拼音

不知道哪里记录下来的文章了,记录一下,方便以后查看

 

create or replace package body Pkg_Krs_Utils is

--
----------------------------------------------------------------------------------------------------------------------------------------------------
--

function GetPY(
   Name in varchar2,
   p_PYType number,          -- 判断拼音首字母 0 或 拼音全拼 1
   out_code   out  number   --返回值(0=成功 -9=失败)
)
return varchar2  is

i_Insert number;
out_word varchar2(32767);

----返回拼音首字母使用变量

lv_temp varchar2(4000);
lv_bytes Varchar2(200);
lv_char Varchar2(10);
li_bytes Integer;
li_pos Integer;

--返回拼音全字母变量

s varchar2(32767):='吖1a0阿1a1嗄1a2哎2ai1啀2ai2毐2ai3艾2ai4安2an1玵2an2垵2an3犴2an4肮3ang1岇3ang2枊3ang4凹2ao1坳2ao4柪2ao1敖2ao2抝2ao3岙2ao4八2ba1叐2ba2把2ba3坝2ba4挀3bai1白3bai2百3bai3呗3bai4扳3ban1阪3ban3'||
'办3ban4邦4bang1绑4bang3玤4bang4勹3bao1窇3bao2嫑4biao2雹3bao2宝3bao3勽3bao4萡2bo2陂3bei1北3bei2鉳3bei3贝3bei4奔3ben1本3ben3坌3ben4伻4beng1甭4beng2埄4beng3泵4beng4皀2bi1荸2bi2匕2bi3币2bi4边4bian1贬4bian2扁4bian3卞4bian4'||
'灬4biao1表4biao2俵4biao4憋3bie1別3bie2瘪3bie3彆3bie4汃3bin1摈3bin4冫4bing1丙4bing3并4bing4癶2bo1仢2bo2蚾2bo3譒2bo4峬2bu1轐2bu2卜2bu3不2bu4嚓2ca1礤2ca3遪2ca4偲3cai1才3cai2采3cai3菜3cai4参3can1残3can2惨3can3'||
'灿3can4仓4cang1匨4cang2賶4cang4撡3cao1曺3cao2艹3cao3肏3cao4冊2ce4嵾3cen1岑3cen2叉3cha1秅3cha2衩3cha3奼3cha4拆4chai1犲4chai2茝4chai3虿4chai4辿4chan1婵4chan2产4chan3忏4chan4伥5chang1长5chang2厂5chang3怅5chang4抄4chao1牊4chao2吵4chao3'||
'仦4chao4车3che1扯3che3屮3che4抻4chen1尘4chen2趻4chen3闯6chuang3衬4chen4阷5cheng1丞5cheng2侱5cheng3秤5cheng4吃3chi1弛3chi2尺3chi3彳3chi4充5chong1虫5chong2宠5chong3铳5chong4抽4chou1仇4chou2丑4chou3臭4chou4榋3chu1刍3chu2杵3chu3处3chu4搋5chuai1'||
'膗5chuai2揣5chuai3啜5chuai4巛5chuan1传5chuan2舛5chuan3汌5chuan4刅6chuang1囱4cong1疮6chuang1床6chuang2傸6chuang3创6chuang4吹4chui1垂4chui2旾4chun1纯4chun2偆4chun3踔4chuo1辶4chuo4呲2ci1词2ci2此2ci3朿2ci4从4cong2匆4cong1丛4cong2憁4cong4凑3cou4粗2cu1'||
'徂2cu2促2cu4汆4cuan1攅4cuan2窜4cuan4崔3cui1漼3cui3伜3cui4邨3cun1存3cun2刌3cun3寸3cun4搓3cuo1髊2ci1虘3cuo2脞3cuo3剉3cuo4咑2da1达2da2打2da3大2da4?ta4呆3dai1歹3dai3代3dai4丹3dan1伔3dan3旦3dan4当4dang1挡4dang3'||
'氹4dang4刀3dao1捯3dao2导3dao3到3dao4恴2de2的2de1揼4beng4扥3den4灯4deng1等4deng3邓4deng4仾2di1廸2di2氐2di3地2di4嗲3dia3敁4dian1典4dian3电4dian4刁4diao1扚4diao3弔4diao4爹3die1苵3die2丁4ding1奵4ding3订4ding4丟3diu1东4dong1'||
'董4dong3动4dong4吺3dou1艔3dao4斗3dou4阧3dou3豆3dou4剢2du1毒2du2笃2du3芏2du4耑4duan1短4duan3段4duan4垖3dui1队3dui4镦3dun1盹3dun3伅3dun4多3duo1仛3duo2朵3duo3刴3duo4妸1e1讹1e2枙1e3厄1e4奀2en1峎2en3摁2en4'||
'鞥3eng1乻2er1儿2er2尒2er3二2er4发2fa1乏2fa2佱2fa3珐2fa4帆3fan1凡3fan2反3fan3氾3fan4匚4fang1防4fang2仿4fang3放4fang4飞3fei1肥3fei2朏3fei3吠3fei4分3fen1坆3fen2粉3fen3份3fen4丰4feng1冯4feng2讽4feng3凤4feng4仏2fo2'||
'佛2fu2紑3fou2缶3fou3夫2fu1乀2fu2呒2fu3父2fu4猤3gui4旮2ga1钆2ga2尕2ga3尬2ga4侅3gai1忋3gai3丐3gai4干3gan1仠3gan3旰3gan4冈4gang1港4gang3杠4gang4皋3gao1夰3gao3告3gao4戈2ge1呄2ge2哿2ge3个2ge4给3gei3根3gen1'||
'哏3gen2亘3gen4更4geng1郠4geng3亙3gen4堩4geng4喼3jie1嗰2ge3工4gong1廾4gong3共4gong4贑3gan4勾3gou1岣3gou3坸3gou4估2gu1鶻2gu2夃2gu3固2gu4瓜3gua1剐3gua3卦3gua4乖4guai1拐4guai3夬4guai4关4guan1馆4guan3卝4guan4光5guang1广5guang3'||
'俇5guang4归3gui1宄3gui3攰3gui4丨3gun3棍3gun4呙3guo1囯3guo2果3guo3鐹3guo4铪2ha1咍3hai1孩3hai2海3hai3亥3hai4爳3han1邗3han2罕3han3鬫3kan4汉3han4夯4hang1魧4hang2沆4hang4茠3hao1蚝3hao2好3hao3号3hao4诃2he1禾2he2贺2he4'||
'?hei1嬒3hui4拫3hen2佷3hen3恨3hen4亨4heng1姮4heng2啈4heng4堼4feng1囍2xi3乊2ho1叿4hong1仜4hong2晎4hong3讧4hong4侯3hou2吼3hou3后3hou4乎2hu1囫2hu2乕2hu3互2hu4花3hua1华3hua2化3hua4蘳3hui1怀4huai2坏4huai4欢4huan1还4huan2'||
'睆4huan3輐3wan4緩4huan3攌4huan4巟5huang1皇5huang2怳5huang3滉5huang4灰3hui1囘3hui2悔3hui3卉3hui4昏3hun1忶3hun2繉5sheng1轋3hun1诨3hun4吙3huo1佸3huo2火3huo3沎3huo4蒦3huo4夻3hua4丌2ji1迹2ji4剞2ji1亼2ji2几2ji3彐3xve3彑2ji4'||
'加3jia1圿3jia2岬3jia3价3jia4戋4jian1籛4jian3见4jian4江5jiang1讲5jiang3匞5jiang4艽4jiao1臫4jiao3叫4jiao4阶3jie1卩3jie2她2ta1姐3jie3丯3jie4藉2ji2繲3xie4巾3jin1仅3jin3伒3jin4坕4jing1井4jing3妌4jing4冂5jiong1冏5jiong3丩3jiu1九3jiu3'||
'匛3jiu4居2jv1局2jv2咀2jv3巨2jv4姢4jvan1卷4jvan3奆4jvan4噘3jve1亅3jve2军3jvn1呁3jvn4咔2ka1卡2ka3开3kai1凯3kai3忾3kai4刊3kan1冚3kan3看3kan4忼4kang1扛4kang2亢4kang4尻3kao1丂3kao3考3kao4?ke1壳2ke2翗2ke3克2ke4'||
'肎3ken3掯3ken4劥4keng1孔4kong3控4kong4抠3kou1口3kou3叩3kou4扝2ku1狜2ku3库2ku4夸3kua1侉3kua3挎3kua4蒯4kuai3巜4kuai4宽4kuan1梡4kuan3匡5kuang1抂5kuang2夼5kuang3邝5kuang4亏3kui1奎3kui2傀3kui3尯3kui4坤3kun1悃3kun3困3kun4扩3kuo4'||
'垃2la1旯2la2腊2la4来3lai2唻3lai4兰3lan2览3lan3烂3lan4啷4lang1勆4lang2朗4lang3埌4lang4唥4leng2捞3lao1劳3lao2老3lao3涝3lao4仂2le4雷3lei2厽3lei3泪3lei4塄4leng2冷4leng3倰4leng4唎2li1刕2li2礼2li3力2li4俩3lia3嫾4lian2'||
'敛4lian3练4lian4良5liang2両5liang3亮5liang4蹽4liao1辽4liao2钌4liao3尥4liao4咧3lie2埓3lie4厸3lin2菻3lin3吝3lin4拎4ling1伶4ling2袊4ling3令4ling4溜3liu1刘3liu2柳3liu3六3liu4囖3luo2咯2ge1龙4long2陇4long3哢4long4娄3lou2嵝3lou3陋3lou4'||
'露2lu4噜2lu1卢2lu2卤2lu3圥2lu4孪4luan2卵4luan3乱4luan4抡3lun1仑3lun2论3lun4捋3luo1罗3luo2剆3luo3泺3luo4驴2lv2吕2lv3虑2lv4掠3lve4嘸2fu3呣3mou2亇2ma1蔴2ma2马2ma3杩2ma4吗2ma1埋3mai2买3mai3劢3mai4颟3man1'||
'悗3man2屘3man3曼3man4牤4mang1吂3man2莽3man3猫3mao1毛3mao2冇3mao3冃3mao4庅2me1沒3mei2毎3mei3妹3mei4椚3men1门3men2掹4meng1氓4mang2罞3mao2莔4meng2勐4meng3孟4meng4咪2mi1弥2mi2米2mi3冖2mi4宀4mian2丏4mian3靣4mian4喵4miao1'||
'苗4miao2杪4miao3妙4miao4乜3mie1灭3mie4民3min2皿3min3名4ming2佲4ming3命4ming4谬3miu4摸2mo1尛2mo2抹2mo3末2mo4哞3mou1牟3mou2某3mou3母2mu3木2mu4拏2na2乸2na3那2na4孻3nai2乃3nai3奈3nai4囡3nan1男3nan2赧3nan3婻3nan4'||
'囔4nang1乪4nang2擃4nang3儾4nang4孬3nao1呶3nao2垴3nao3闹3nao4疒2ne4呢2ne1娞3nei3內3nei4嫩3nen4妮2ni1尼2ni2伱2ni3檷2ni4拈4nian1年4nian2涊4nian3卄4nian4娘5niang2酿5niang4鸟4niao3尿4niao4捏3nie1圼3nie4脌3nin1囜3nin2拰3nin3'||
'宁4ning2矃4ning3佞4ning4妞3niu1牛3niu2忸3niu3农4nong2繷4nong3弄4nong4羺3nou2啂3nou4奴2nu2努2nu3怒2nu4奻4nuan2渜4nuan3郍2na4挪3nuo2诺3nuo4女2nv3衂2nv4疟3nve4筽2ou1吘2ou3怄2ou4妑2pa1杷2pa2帊2pa4拍3pai1俳3pai2'||
'哌3pai4眅3pan1爿3pan2坢3pan3冸3pan4乓4pang1厐4pang2嗙4pang3炐4pang4抛3pao1刨3pao2奅3pao4呸3pei1阫3pei2俖3pei3伂3pei4喷3pen1瓫3pen2呠3pen3喯3pen4匉4peng1芃4peng2捧4peng3掽4peng4丕2pi1皮2pi2匹2pi3屁2pi4片4pian1骈4pian2'||
'覑4pian3骗4pian4剽4piao1瓢4piao2殍4piao3票4piao4氕3pie1撇3pie3嫳3pie4姘3pin1玭3pin2品3pin3牝3pin4乒4ping1平4ping2钋2po1婆2po2叵2po3廹2po4剖3pou1抔3pou2咅3pou3仆2pu2攴2pu1圤2pu2朴2pu3舗2pu4七2qi1亓2qi2乞2qi3'||
'气2qi4掐3qia1拤3qia3圶3qia4千4qian1仱4qian2凵4qian3欠4qian4呛5qiang1強5qiang2抢5qiang3炝5qiang4悄4qiao1乔4qiao2巧4qiao3俏4qiao4切3qie4苆3qie1茄3qie2且3qie3厒3qie4亲3qin1庈3qin2赾3qin3吢3qin4靑4qing1夝4qing2苘4qing3庆4qing4宆5qiong2'||
'丘3qiu1叴3qiu2搝3qiu3区2qv1佢2qv2取2qv3厺2qv4峑4qvan2犭4qvan3劝4qvan4炔3qve1瘸3qve2却3qve4夋3qvn1峮3qvn2亽2ra1呥3ran2冄3ran3穣4rang2荛3rao2扰3rao3绕3rao4惹2re3热2re4人3ren2忍3ren3刃3ren4扔4reng1仍4reng2日2ri4'||
'戎4rong2冗4rong3厹3rou2韖3rou3肉3rou4嶿2ru2汝2ru3入2ru4堧4ruan2阮4ruan3桵3rui3汭3rui4闰3run4挼3ruo2叒3ruo4仨2sa1洒2sa3卅2sa4愢3sai1赛3sai4壭3san1伞3san3俕3san4桒4sang1嗓4sang3丧4sang4掻3sao1扫3sao3瘙3sao4色2se4'||
'森3sen1僧4seng1杀3sha1傻3sha3倽3sha4筛4shai1晒4shai4山4shan1闪4shan3讪4shan4伤5shang1裳5shang3丄5shang4弰4shao1勺4shao2少4shao3劭4shao4奢3she1舌3she2舍3she4申4shen1神4shen2审4shen3肾4shen4升5sheng1渑5sheng2省5sheng3圣5sheng4尸3shi1十3shi2'||
'史3shi3士3shi4収4shou1扌4shou3寿4shou4书3shu1秫3shu2属3shu3朮3shu4刷4shua1耍4shua3誜4shua4衰5shuai1甩5shuai3帅5shuai4闩5shuan1涮5shuan4双6shuang1爽6shuang3谁4shui2氵4shui3帨4shui4吮4shun3顺4shun4说4shuo1妁4shuo4厶2si1死2si3巳2si4忪4song1'||
'怂4song3讼4song4凁3sou1螋3sou3瘶3sou4苏2su1俗2su2玊2su4狻4suan1匴4suan3祘4suan4夊3sui1绥3sui2膸3sui3亗3sui4孙3sun1损3sun3潠3sun4唆3suo1所3suo3逤3suo4侤2ta1塔2ta3挞2ta4囼3tai1台3tai2太3tai4坍3tan1坛3tan2忐3tan3'||
'叹3tan4汤4tang1镗4tang2帑4tang3烫4tang4仐3tao1匋3tao2讨3tao3套3tao4忑2te4膯4teng1疼4teng2霯4teng4剔2ti1厗2ti2体2ti3戻2ti4天4tian1田4tian2忝4tian3舚4tian4旫4tiao1芀4tiao2宨4tiao3眺4tiao4怗3tie1铁3tie3飻3tie4厅4ting1邒4ting2'||
'圢4ting3炵4tong1仝4tong2统4tong3恸4tong4偷3tou1亠3tou2妵3tou3透3tou4凸2tu1図2tu2土2tu3兎2tu4湍4tuan1团4tuan2疃4tuan3彖4tuan4推3tui1颓3tui2俀3tui3退3tui4吞3tun1黗3tun2氽3tun3乇3tuo1驝3tuo2彵3tuo3拓3tuo4屲2wa1瓦2wa3'||
'袜2wa4歪3wai1崴3wai3外3wai4乛3wan1丸3wan2宛3wan3万3wan4尣4wang1亡4wang2网4wang3妄4wang4危3wei1囗3wei2伟3wei3卫3wei4昷3wen1文3wen2刎3wen3问3wen4翁4weng1瓮4weng4挝2wo1我2wo3仴2wo4乌2wu1无2wu2五2wu3兀2wu4夕2xi1'||
'习2xi2杫2xi3匸2xi4呷3xia1匣3xia2閜3xia3丅3xia4仙4xian1伭4xian2冼4xian3县4xian4乡5xiang1瓨5xiang2享5xiang3向5xiang4灱4xiao1洨4xiao2小4xiao3孝4xiao4些3xie1劦3xie2写3xie3伳3xie4忄3xin1枔3xin2伈3xin3伩3xin4兴4xing1刑4xing2睲4xing3'||
'杏4xing4凶5xiong1雄5xiong2诇5xiong4休3xiu1苬3xiu2糔3xiu3秀3xiu4戌2xv1俆2xv2许2xv3旭2xv4吅4xvan1玄4xvan2选4xvan3怰4xvan4疶3xve1穴3xve2雪3xve3血3xve4坃3xve1廵3xvn2驯3xvn4杊3xvn2卂3xvn4丫2ya1牙2ya2厊2ya3劜2ya4咽3yan1'||
'讠3yan2夵3yan3厌3yan4央4yang1扬4yang2岟4yang3怏4yang4幺3yao1爻3yao2仸3yao3穾3yao4亪2ye1爷2ye2也2ye3业2ye4一2yi1乁2yi2乙2yi3乂2yi4囙3yin1冘3yin2廴3yin3印3yin4应4ying1盁4ying2矨4ying3用4yong4优3you1尢3you2友3you3'||
'又3you4扜2yv1于2yv2与2yv3蘌2yv4囦4yvan]元4yvan2远4yvan3夗4yvan4曰3yve1月3yve4蒀3yvn1云3yvn2允3yvn3孕3yvn4帀2za1杂2za2災3zai1宰3zai3再3zai4兂3zan1咱3zan2昝3zan3暂3zan4牂4zang1驵4zang3奘4zang4脏4zang1塟4zang4傮3zao1'||
'凿3zao2早3zao3灶3zao4啫2ze2夨2ze4贼3zei2怎3zen3囎4zeng1曾4ceng2増4zeng1锃4zeng4吒3zha1闸3zha2厏3zha3乍3zha4夈4zhai1宅4zhai2窄4zhai3债4zhai4沾4zhan1讝4zhan2占4zhan4张5zhang1涨5zhang3丈5zhang4佋4zhao1爫4zhao3召4zhao4蜇3zhe1厇3zhe2'||
'者3zhe3这3zhe4贞4zhen1屒4zhen3圳4zhen4争5zheng1氶5zheng3正5zheng4之3zhi1执3zhi2夂3zhi3至3zhi4中5zhong1肿5zhong3仲5zhong4州4zhou1妯4zhou2肘4zhou3纣4zhou4朱3zhu1竹3zhu2丶3zhu3伫3zhu4抓4zhua1爪4zhua3拽5zhuai1专5zhuan1转5zhuan4妆6zhuang1壮6zhuang4'||
'隹4zhui1沝4zhui3坠4zhui4宒4zhun1准4zhun3訰4zhun4卓4zhuo2拙4zhuo1蠿4zhuo2仔2zi2孖2zi1籽2zi3字2zi4宗4zong1总4zong3纵4zong4邹3zou1赱3zou3奏3zou4租2zu1卆2zu2诅2zu3躜4zuan1繤4zuan3钻4zuan4厜3zui1嶊3zui3栬3zui4尊3zun1僔3zun3'||
'捘3zun4昨3zuo2左3zuo3让4rang4作3zuo4谈3tan2学3xue2';
l   integer:=length(s);
c1  varchar2(32767):='';
c2  varchar2(2);
c3  varchar2(10);
c4  varchar2(10);
c5  varchar2(16);
type t is table of varchar2(10) index by binary_integer;
tc3 t;
c6  varchar2(2);
p1  integer;
p2  integer;
p3  integer;


begin
   If Name Is Null Then
      Return '' ;
   End If;  
  
     if p_PYType = 0 then          --返回汉字拼音的首字母
        For i In 1..length(Name) Loop
          lv_char := substr(Name,i,1);
       
          --ZHS16GBK
          If lengthb(lv_char) = 2 Then
           Select replace(substrb(dump(lv_char,1010),instrb(dump(lv_char,1010),'ZHS16GBK:')),'ZHS16GBK: ','') Into lv_bytes from dual;
          --UTF8
          elsIf lengthb(lv_char) = 3 Then
           Select replace(substrb(dump(convert(lv_char,'ZHS16GBK','UTF8'),1010),instrb(dump(convert(lv_char,'ZHS16GBK','UTF8'),1010),'UTF8:')),'UTF8: ','')
          Into lv_bytes from dual;
          end if;
         if lv_bytes is not null then
          li_pos:=instr(lv_bytes,',');
          li_bytes:=substr(lv_bytes,1,li_pos-1)*256+substr(lv_bytes,li_pos+1);
          if ( li_bytes < to_number('B0A1','xxxx')) Then
          lv_temp:=lv_temp||'*';
          Elsif ( li_bytes < to_number('B0C5','xxxx')) Then
          lv_temp:=lv_temp||'a';
          Elsif ( li_bytes < to_number('B2C1','xxxx')) Then
          lv_temp:=lv_temp||'b';
          Elsif ( li_bytes < to_number('B4EE','xxxx')) Then
          lv_temp:=lv_temp||'c';
          Elsif ( li_bytes < to_number('B6EA','xxxx')) Then
          lv_temp:=lv_temp||'d';
          Elsif ( li_bytes < to_number('B7A2','xxxx')) Then
          lv_temp:=lv_temp||'e';
          Elsif ( li_bytes < to_number('B8C1','xxxx')) Then
          lv_temp:=lv_temp||'f';
          Elsif ( li_bytes < to_number('B9FE','xxxx')) Then
          lv_temp:=lv_temp||'g';
          Elsif ( li_bytes < to_number('BBF7','xxxx')) Then
          lv_temp:=lv_temp||'h';
          Elsif ( li_bytes < to_number('BFA6','xxxx')) Then
          lv_temp:=lv_temp||'j';
          Elsif ( li_bytes < to_number('C0AC','xxxx')) Then
          lv_temp:=lv_temp||'k';
          Elsif ( li_bytes < to_number('C2E8','xxxx')) Then
          lv_temp:=lv_temp||'l';
          Elsif ( li_bytes < to_number('C4C3','xxxx')) Then
          lv_temp:=lv_temp||'m';
          Elsif ( li_bytes < to_number('C5B6','xxxx')) Then
          lv_temp:=lv_temp||'n';
          Elsif ( li_bytes < to_number('C5BE','xxxx')) Then
          lv_temp:=lv_temp||'o';
          Elsif ( li_bytes < to_number('C6DA','xxxx')) Then
          lv_temp:=lv_temp||'p';
          Elsif ( li_bytes < to_number('C8BB','xxxx')) Then
          lv_temp:=lv_temp||'q';
          Elsif ( li_bytes < to_number('C8F6','xxxx')) Then
          lv_temp:=lv_temp||'r';
          Elsif ( li_bytes < to_number('CBFA','xxxx')) Then
          lv_temp:=lv_temp||'s';
          Elsif ( li_bytes < to_number('CDDA','xxxx')) Then
          lv_temp:=lv_temp||'t';
          Elsif ( li_bytes < to_number('CEF4','xxxx')) Then
          lv_temp:=lv_temp||'w';
          Elsif ( li_bytes < to_number('D1B9','xxxx')) Then
          lv_temp:=lv_temp||'x';
          Elsif ( li_bytes < to_number('D4D1','xxxx')) Then
          lv_temp:=lv_temp||'y';
          Elsif ( li_bytes < to_number('D7FA','xxxx')) Then
          lv_temp:=lv_temp||'z';
          Else
          lv_temp:=lv_temp||'*';
          End If;
          Else
          lv_temp:=lv_temp||lv_char;
          End If;
          End Loop;
         ----DBMS_OUTPUT.put_line('test'||lv_temp);
         out_word :=upper(lv_temp);
      elsif p_PYType=1 then           --返回汉字拼音
              --DBMS_OUTPUT.put_line('NAME='||name||'p_PYType='||p_PYType);
              for i in 1..length(name)       
               loop             
                c2:=substr(name,i,1);    
                p1:=floor(ascii(c2)/256);
                p2:=mod(ascii(c2),256);
                --DBMS_OUTPUT.put_line('start if c2='||ascii(c2));
             
               if ascii(c2) between 1 and 128 then --ascii              
                  c5:=c2;
               elsif p1=127 or p2=255  or (p2 between 0 and 63) then                   
                   if not (nlssort(c2,'NLS_SORT=SCHINESE_STROKE_M')>nlssort('鶑','NLS_SORT=SCHINESE_STROKE_M')
                          and nlssort(c2,'NLS_SORT=SCHINESE_STROKE_M')                           or ascii(c2) in (41398,41399)then
                   c5:=c2 ;
                   else
                   c5:='.';
                   end if;                
                 else                                         
                    p1:=to_number(instr(s,c2,1,1));  
                    --DBMS_OUTPUT.put_line(' else p1='||p1);                                       
                    if p1>0 then
                       p2:=to_number(substr(s,p1+1,1));
                       --DBMS_OUTPUT.put_line(' else p2='||p2);
                       c3:=substr(s,p1+2,p2+1); 
                       --DBMS_OUTPUT.put_line(' else c3='||c3);                  
                    else                  
                       if tc3.count<2 then                      
                           p1:=1;
                           for i in 1..4000 --得到排序字符串的SQL
                             loop
                               exit when p1>=l;
                               p2:=substr(s,p1+1,1);
                               c4:=substr(s,p1,p2+3);
                               tc3(tc3.count+1):=c4;
                               p1:=p1+length(c4);
                             end loop;
                        
                       end if;
                         for i in 2..tc3.count
                            loop
                            if nlssort(substr(tc3(i),1,1),'nls_sort=schinese_pinyin_m')>
                               nlssort(c2,'nls_sort=schinese_pinyin_m') then
                               c3:=tc3(i-1);
                               exit;
                            elsif i=tc3.count then
                               c3:=tc3(i);
                            end if;
                            end loop;
                            c3:=substr(c3,3);
                    end if;

                  if    instr(c3,'ia',1,1)>0 or
                        instr(c3,'ua',1,1)>0 or
                        instr(c3,'va',1,1)>0 then --取要注音的元音,ia注音在a上,其它在第一个元音上
                      c6:='a';
                  elsif instr(c3,'ue',1,1)>0 or
                        instr(c3,'ie',1,1)>0 or
                        instr(c3,'ve',1,1)>0 then
                      c6:='e';
                  elsif instr(c3,'ui',1,1)>0 or
                        instr(c3,'ai',1,1)>0 then
                      c6:='i';
                  elsif instr(c3,'uo',1,1)>0 or
                        instr(c3,'io',1,1)>0 then
                      c6:='o';
                  elsif instr(c3,'iu',1,1)>0 then
                      c6:='u';
                  else
                    c6:=substr(c3,1,1);
                    if not c6 in ('a','e','i','o','u','v') then
                       c6:=substr(c3,2,1);
                       if not c6 in ('a','e','i','o','u','v') then
                       c6:=substr(c3,3,1);
                       end if;
                    end if;
                  end if;
                  if substr(c3,1,2) in ('jv','qv','xv','yv') then
                     c3:=substr(c3,1,1)||'u'||substr(c3,3);
                  elsif substr(c3,2,1)='v' and c6<>'v' then
                     c3:=substr(c3,1,1)||'ü'||substr(c3,3);
                  end if;
                           
                  p3:=to_number(substr(c3,length(c3),1));                    
                  c3:=substr(c3,1,length(c3)-1);
                --DBMS_OUTPUT.put_line(' else c6='||c6);    
                ---- 带出汉字
                --  select c2||'['||replace(c3,c6,decode(c6||p3,
                --                      'a0','a','a1','ā','a2','á','a3','ǎ','a4','à',
                --                       'e0','e','e1','ē','e2','é','e3','ě','e4','è',
                --                      'i0','i','i1','ī','i2','í','i3','ǐ','i4','ì',
                --                      'o0','o','o1','ō','o2','ó','o3','ǒ','o4','ò',
                --                       'u0','u','u1','ū','u2','ú','u3','ǔ','u4','ù',
                --                       'v0','ü','v1','ǖ','v2','ǘ','v3','ǚ','v4','ǜ'
                --                      ))||'] '
                --DBMS_OUTPUT.put_line(' else c2='||c2);
                select replace(c3,c6,decode(c6||p3,
                                       'a0','a','a1','ā','a2','á','a3','ǎ','a4','à',
                                       'e0','e','e1','ē','e2','é','e3','ě','e4','è',
                                       'i0','i','i1','ī','i2','í','i3','ǐ','i4','ì',
                                       'o0','o','o1','ō','o2','ó','o3','ǒ','o4','ò',
                                       'u0','u','u1','ū','u2','ú','u3','ǔ','u4','ù',
                                       'v0','ü','v1','ǖ','v2','ǘ','v3','ǚ','v4','ǜ'
                                       ))||' '
                    into c5 from dual ;
                  
                end if;
                c1:=c1||c5;
                       
              end loop;        
              ----DBMS_OUTPUT.put_line(' else c1='||c1);  
              out_word:=c1;
              ----DBMS_OUTPUT.put_line(' else out_word='||out_word);  
         end if;
    
out_code := 0;
return out_word;
exception
     when others then
          out_code := -9;
          pkg_pub.FSetDebugInfo(sqlcode||sqlerrm,null,null,i_Insert);
          return(Name);

end GetPY;

--
----------------------------------------------------------------------------------------------------------------------------------------------------
--


end Pkg_Krs_Utils;

你可能感兴趣的:(oracle 8i 中文转拼音)