汉字转成拼音

CREATE OR REPLACE FUNCTION GetHzPYCAP(p_String varchar2) --?????
 RETURN VARCHAR2 IS
--declare
 --p_String varchar2(200) := '???????';
 v_char varchar2(2);  --????
 n_loop number;    --??
 n_len number;     --????
 n_ascii number;   --??ASCII?
 n_ord_high number; --n_ascii/156
 n_ord_low number;  --n mod 256
 n_temp number;
 n_temp1 number;
 v_PY varchar2(32767);

BEGIN

if p_String IS NULL  then
  RETURN '';
 end if;

  v_PY := '';
  n_len := length(p_String);
  FOR n_loop IN 1..n_len LOOP
    v_char := substr(p_string,n_loop,1);
    IF upper(v_char) IN (
        'A','B','C','D','E','F','G',
        'H','I','J','K','L','M','N',
        'O','P','Q','R','S','T',
        'U','V','W','X','Y','Z',
        '0','1','2','3','4','5','6','7','8','9',
        '(', ')', '[', ']','.', '!', '@', '#', '$',
        '%', '^', '&', '*', '-', '+','<', '>', '?', ':', '"')  THEN
      v_PY := v_PY||v_char;
    ELSE
        n_ascii := ascii(v_char);
        n_ord_high := trunc(n_ascii/256,0);
        n_ord_low := n_ascii-(n_ord_high*256);
        --DBMS_OUTPUT.PUT_LINE('n_ascii = '||to_char(n_ascii,'9999999'));
        --DBMS_OUTPUT.PUT_LINE('n_ord_high = '||to_char(n_ord_high,'9999999'));
        --DBMS_OUTPUT.PUT_LINE('n_ord_low = '||to_char(n_ord_low,'9999999'));
        IF (n_ord_high>128) and (n_ord_low>63) THEN
          CASE n_ord_high
            WHEN 162 THEN     --????
              IF n_ord_low>160 THEN
                v_PY := v_PY||get_roma_num_py(n_ord_low-160);
              END IF;
            WHEN 163 THEN     --??ASCII
              IF n_ord_low>128 THEN
                v_char := chr(n_ord_low-128);
                IF upper(v_char) IN (
                   'A','B','C','D','E','F','G',
                   'H','I','J','K','L','M','N',
                   'O','P','Q','R','S','T',
                   'U','V','W','X','Y','Z',
                   '0','1','2','3','4','5','6','7','8','9',
                   '(', ')', '[', ']') THEN
                  v_PY := v_PY||v_char;
                END IF;
              END IF;
            WHEN 166 THEN     --????
              IF (n_ord_low>160) AND (n_ord_low<185) THEN --A1--B8
                v_PY := v_PY||get_greece_alphabet_py(n_ord_low-160);
              ELSE
                IF (n_ord_low>192) AND (n_ord_low<217) THEN --C1--D8
                  v_PY := v_PY||get_greece_alphabet_py(n_ord_low-192);
                END IF;
              END IF;
            ELSE
            BEGIN
              n_temp := n_ord_high-128;
              n_ord_low := n_ord_low-63;
              n_temp1 := trunc(n_temp/10,0);
              n_temp1 := n_temp-n_temp1*10;
              IF n_temp1=0 THEN
                n_temp1 := 10;
              END IF;
              --DBMS_OUTPUT.PUT_LINE('n_temp = '||to_char(n_temp,'9999999'));
              --DBMS_OUTPUT.PUT_LINE('n_temp1 = '||to_char(n_temp1,'9999999'));
              CASE
              WHEN n_temp<11 THEN
                n_temp1 := get_py_index_01(n_temp1,n_ord_low);
              WHEN n_temp<21 THEN
                n_temp1 := get_py_index_02(n_temp1,n_ord_low);
              WHEN n_temp<31 THEN
                n_temp1 := get_py_index_03(n_temp1,n_ord_low);
              WHEN n_temp<41 THEN
                n_temp1 := get_py_index_04(n_temp1,n_ord_low);
              WHEN n_temp<51 THEN
                n_temp1 := get_py_index_05(n_temp1,n_ord_low);
              WHEN n_temp<61 THEN
                n_temp1 := get_py_index_06(n_temp1,n_ord_low);
              WHEN n_temp<71 THEN
                n_temp1 := get_py_index_07(n_temp1,n_ord_low);
              WHEN n_temp<81 THEN
                n_temp1 := get_py_index_08(n_temp1,n_ord_low);
              WHEN n_temp<91 THEN
                n_temp1 := get_py_index_09(n_temp1,n_ord_low);
              WHEN n_temp<101 THEN
                n_temp1 := get_py_index_10(n_temp1,n_ord_low);
              WHEN n_temp<111 THEN
                n_temp1 := get_py_index_11(n_temp1,n_ord_low);
              WHEN n_temp<121 THEN
                n_temp1 := get_py_index_12(n_temp1,n_ord_low);
              WHEN n_temp<121 THEN
                n_temp1 := get_py_index_13(n_temp1,n_ord_low);
              ELSE
                n_temp1 := 0;
              END CASE;
              v_PY := v_PY||substr(GetHzPY_by_index(n_temp1),1,1);
            END;
          END CASE;
        END IF;
    END IF;
  END LOOP;
  RETURN v_PY;
  --DBMS_OUTPUT.PUT_LINE(v_PY);
END GetHzPYCAP;
/


CREATE OR REPLACE FUNCTION FTGM.GetHzPY_by_index(
  p_PY_Index number)
 RETURN VARCHAR2 IS
 v_PY_List THZPY_LIST :=  THZPY_LIST(
    'a',      'aes',    'ai',     'an',     'ang',    'ao',     'ba',     'bai',    'baike',  'baiwa',
    'ban',    'bang',   'bao',    'be',     'bei',    'ben',    'beng',   'bi',     'bia',    'bian',
    'biao',   'bie',    'bin',    'bing',   'bo',     'bu',     'ca',     'cai',    'cal',    'can',
    'cang',   'cao',    'ce',     'cen',    'ceng',   'ceok',   'ceom',   'ceon',   'ceor',   'cha',
    'chai',   'chan',   'chang',  'chao',   'che',    'chen',   'cheng',  'chi',    'chong',  'chou',
    'chu',    'chua',   'chuai',  'chuan',  'chuang', 'chui',   'chun',   'chuo',   'ci',     'cis',
    'cong',   'cou',    'cu',     'cuan',   'cui',    'cun',    'cuo',    'da',     'dai',    'dan',
    'dang',   'dao',    'de',     'defa',   'dei',    'deli',   'dem',    'den',    'deng',   'deo',
    'di',     'dia',    'dian',   'diao',   'die',    'dim',    'ding',   'diu',    'dong',   'dou',
    'du',     'duan',   'dug',    'dui',    'dul',    'dun',    'duo',    'e',      'ei',     'en',
    'eng',    'eo',     'eol',    'eom',    'eos',    'er',     'fa',     'fan',    'fang',   'fei',
    'fen',    'feng',   'fenwa',  'fiao',   'fo',     'fou',    'fu',     'fui',    'ga',     'gad',
    'gai',    'gan',    'gang',   'gao',    'ge',     'gei',    'gen',    'geng',   'geo',    'geu',
    'gib',    'go',     'gong',   'gongli', 'gou',    'gu',     'gua',    'guai',   'guan',   'guang',
    'gui',    'gun',    'guo',    'ha',     'hai',    'hal',    'han',    'hang',   'hao',    'haoke',
    'he',     'hei',    'hem',    'hen',    'heng',   'heui',   'ho',     'hol',    'hong',   'hou',
    'hu',     'hua',    'huai',   'huan',   'huang',  'hui',    'hun',    'huo',    'hwa',    'hweong',
    'i',      'ji',     'jia',    'jialun', 'jian',   'jiang',  'jiao',   'jie',    'jin',    'jing',
    'jiong',  'jiu',    'jou',    'ju',     'juan',   'jue',    'jun',    'ka',     'kai',    'kal',
    'kan',    'kang',   'kao',    'ke',     'keg',    'kei',    'kem',    'ken',    'keng',   'keo',
    'keol',   'keop',   'keos',   'keum',   'ki',     'kong',   'kos',    'kou',    'ku',     'kua',
    'kuai',   'kuan',   'kuang',  'kui',    'kun',    'kuo',    'kweok',  'kwi',    'la',     'lai',
    'lan',    'lang',   'lao',    'le',     'lei',    'lem',    'len',    'leng',   'li',     'lia',
    'lian',   'liang',  'liao',   'lie',    'lin',    'ling',   'liu',    'liwa',   'lo',     'long',
    'lou',    'lu',     'luan',   'lue',    'lun',    'luo',    'lv',     'm',      'ma',     'mai',
    'man',    'mang',   'mangmi', 'mao',    'mas',    'me',     'mei',    'men',    'meng',   'meo',
    'mi',     'mian',   'miao',   'mie',    'min',    'ming',   'miu',    'mo',     'mol',    'mou',
    'mu',     'myeo',   'myeon',  'myeong', 'n',      'na',     'nai',    'nan',    'nang',   'nao',
    'ne',     'nei',    'nem',    'nen',    'neng',   'neus',   'ng',     'ngag',   'ngai',   'ngam',
    'ni',     'nian',   'niang',  'niao',   'nie',    'nin',    'ning',   'niu',    'nong',   'nou',
    'nu',     'nuan',   'nue',    'nun',    'nung',   'nuo',    'nv',     'nve',    'o',      'oes',
    'ol',     'on',     'ou',     'pa',     'pai',    'pak',    'pan',    'pang',   'pao',    'pei',
    'pen',    'peng',   'peol',   'phas',   'phdeng', 'phoi',   'phos',   'pi',     'pian',   'piao',
    'pie',    'pin',    'ping',   'po',     'pou',    'ppun',   'pu',     'q',      'qi',     'qia',
    'qian',   'qiang',  'qianke', 'qianwa', 'qiao',   'qie',    'qin',    'qing',   'qiong',  'qiu',
    'qu',     'quan',   'que',    'qun',    'ra',     'ram',    'ran',    'rang',   'rao',    're',
    'ren',    'reng',   'ri',     'rong',   'rou',    'ru',     'rua',    'ruan',   'rui',    'run',
    'ruo',    'sa',     'saeng',  'sai',    'sal',    'san',    'sang',   'sao',    'se',     'sed',
    'sei',    'sen',    'seng',   'seo',    'seon',   'sha',    'shai',   'shan',   'shang',  'shao',
    'she',    'shei',   'shen',   'sheng',  'shi',    'shike',  'shiwa',  'shou',   'shu',    'shua',
    'shuai',  'shuan',  'shuang', 'shui',   'shun',   'shuo',   'shw',    'si',     'so',     'sol',
    'song',   'sou',    'su',     'suan',   'sui',    'sun',    'suo',    'ta',     'tae',    'tai',
    'tan',    'tang',   'tao',    'tap',    'te',     'tei',    'teng',   'teo',    'teul',   'teun',
    'ti',     'tian',   'tiao',   'tie',    'ting',   'tiu',    'tol',    'ton',    'tong',   'tou',
    'tu',     'tuan',   'tui',    'tun',    'tuo',    'uu',     'wa',     'wai',    'wan',    'wang',
    'wei',    'wen',    'weng',   'wie',    'wo',     'wu',     'xi',     'xia',    'xian',   'xiang',
    'xiao',   'xie',    'xin',    'xing',   'xiong',  'xiu',    'xu',     'xuan',   'xue',    'xun',
    'ya',     'yan',    'yang',   'yao',    'ye',     'yen',    'yi',     'yin',    'ying',   'yo',
    'yong',   'you',    'yu',     'yuan',   'yue',    'yug',    'yun',    'za',     'zad',    'zai',
    'zan',    'zang',   'zao',    'ze',     'zei',    'zen',    'zeng',   'zha',    'zhai',   'zhan',
    'zhang',  'zhao',   'zhe',    'zhei',   'zhen',   'zheng',  'zhi',    'zhong',  'zhou',   'zhu',
    'zhua',   'zhuai',  'zhuan',  'zhuang', 'zhui',   'zhun',   'zhuo',   'zi',     'zo',     'zong',
    'zou',    'zu',     'zuan',   'zui',    'zun',    'zuo'
    );
BEGIN
    IF (p_PY_Index>0) AND (p_PY_Index<527) THEN
       --RETURN  INITCAP(v_PY_List(p_PY_Index));
       RETURN  v_PY_List(p_PY_Index);
    ELSE
      RETURN '';
    END IF;
END GetHzPY_by_index;
/
原文地址:https://www.cnblogs.com/siyunianhua/p/3830859.html