create or replace
FUNCTION md5hash (str IN VARCHAR2)
RETURN VARCHAR2
IS v_checksum VARCHAR2(32);
BEGIN
v_checksum := LOWER( RAWTOHEX( UTL_RAW.CAST_TO_RAW( sys.dbms_obfuscation_toolkit.md5(input_string => str) ) ) );
RETURN v_checksum;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END md5hash;
Ejemplo de uso:
select md5hash('diego') from dual;Resultado:
078c007bd92ddec308ae2f5115c1775d
Si nuestra idea es almacenarlo como raw:
create or replace
FUNCTION md5raw (str IN VARCHAR2)
RETURN RAW
IS v_checksum VARCHAR2(32);
BEGIN
v_checksum := UTL_RAW.CAST_TO_RAW( sys.dbms_obfuscation_toolkit.md5(input_string => str) ) ;
RETURN v_checksum;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END md5raw;
Ejemplo de uso (crear tabla, crear campo, insertar, consultar):
drop table tmp_die_md5;Fuente:
create table tmp_die_md5(md5 raw(16) );
insert into tmp_die_md5 select md5raw('Diego') from dual;
select * from tmp_die_md5 where md5= '4FB845C67D91BCB3178498FC6FE1FEDC' ;
select * from tmp_die_md5 where md5= ( md5raw('Diego'));
http://www.pilcrow.nl/2010/12/md5-function-in-oracle
No hay comentarios:
Publicar un comentario