oracle汉字转换成拼音、五笔等

select ypmc,ch_code(ypmc,'pyCode',1,8) from yk_typk;
第二个参数:码类型(见下图)
第三个参数:从第几位开始截取
第四个参数:截取最大长度


ch_code函数脚本:

CREATE OR REPLACE FUNCTION "CH_CODE" (chStr    varchar2,
                                   codeType varchar2,
                                   len      Integer,
                                   maxLen   Integer) RETURN VARCHAR2 IS
  ch     VARCHAR2(4);
  code   varchar2(50);
  retStr VARCHAR2(100);
BEGIN
  for i in 1 .. length(chStr) loop
    ch := substr(chStr, i, 1);
    if REGEXP_INSTR(ch, '[a-zA-Z0-9]') > 0 or
       (REGEXP_INSTR(asciistr(ch), '[\u4E00-\u9FA5]') > 0 and
        substr(asciistr(ch), 1, 1) = '\') then
      if REGEXP_INSTR(ch, '[a-zA-Z0-9]') > 0 then
        retStr := retStr || ch;
      else
        begin
          execute immediate 'select ' || codeType ||
                            ' from pub_characterencoding t where t.hzcode = :1'
            into code
            using ch;
          retStr := retStr || substr(code, 0, len);
        exception
          when others then
            retStr := '';
        end;
      end if;
    end if;
  end loop;
  return substr(retStr, 0, maxLen);
exception
  when others then
    return '';
END;

pub_characterencoding 表中的数据:点击打开链接 进行下载


版权声明:本文为dhf984721977原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/dhf984721977/article/details/79439290