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;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?