工作需要使用sql对某个字段进行加密处理,创建MD5处理函数如下:
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;
使用示例:
select md5(123) from dual

但是跑数中途遇到如下报错:

检查发现,当md5函数输入参数为空时,导致报错,修改函数如下,解决:
CREATE OR REPLACE FUNCTION MD5( passwd IN VARCHAR2) RETURN VARCHAR2
IS
retval varchar2(32);
BEGIN
retval := (case when passwd is null then null else utl_raw.cast_to_raw(DBMS_OBFUSCATION_TOOLKIT.MD5(INPUT_STRING => passwd)) end);
RETURN retval;
END;
网友评论