Oracle自定义函数:生成汉字首字母拼音码的函数、MD5

1 生成汉字拼音码的函数

使用方法:

select 用户名.函数名(需要获取首字母拼音码的字段名) from 用户名.表名;
select oracle_user1.fgetpy(t.name) from oracle_user1.student t;

函数定义:

复制代码
create or replace function fgetpy(v_str varchar2) return varchar2 as
  v_strlen int;
  v_return varchar2(500);
  v_ii     int;
  v_n      int;
  v_c      varchar2(2);
  v_chn    varchar2(2);
  v_rc     varchar2(500);
  /*************************************************************************
  生成汉字拼音码的函数。 2009-06-21
  **************************************************************************/
begin
  --dbms_output.put_line(v_str);
  v_rc     := v_str;
  v_strlen := length(v_rc);
  v_return := '';
  v_ii     := 0;
  while v_ii < v_strlen loop
    v_ii := v_ii + 1;
    v_n  := 63;
    select substr(v_rc, v_ii, 1) into v_chn from dual;
    select v_n + max(rowsf)
      into v_n
      from (select chn, rownum rowsf
              from (select chn
                      from (select '' chn
                              from dual
                            union
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual --because have no 'i'
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select ''
                              from dual
                            union all
                            select v_chn
                              from dual) a
                     order by nlssort(chn, 'NLS_SORT=SCHINESE_PINYIN_M')) c) b
     where chn = v_chn;
    v_c := chr(v_n);
    if chr(v_n) = '@' then
      --英文直接返回
      v_c := v_chn;
    end if;
    v_return := v_return || v_c;
    v_return := lower(v_return);
  end loop;
  return v_return;
end fgetpy;
复制代码

2 MD5

使用方法:

select 用户名.函数名(需要加密的字段名) from 用户名.表名;
select oracle_user1.md5(t.id) from oracle_user1.student t;

函数定义:

create or replace function md5(passwd in varchar2) return varchar2 is
  retval varchar2(32);
begin
  retval := utl_raw.cast_to_raw(dbms_obfuscation_toolkit.md5(input_string => passwd));
  return retval;
end;
posted @   DAYTOY-105  阅读(45)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示