title: MD5 in Oracle (DBMS_OBFUSCATION_TOOLKIT.MD5)
body: <p>I'm trying to compose a function to obtain MD5 hashes from bits I've gathered here and there. I want to obtain the lower-case hexadecimal representation of the hash. I have this so far:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION MD5 (
      CADENA IN VARCHAR2
  ) RETURN DBMS_OBFUSCATION_TOOLKIT.VARCHAR2_CHECKSUM
  AS
  BEGIN
      RETURN LOWER(
          RAWTOHEX(
              UTL_RAW.CAST_TO_RAW(
                  DBMS_OBFUSCATION_TOOLKIT.MD5(INPUT_STRING =&gt; CADENA)
              )
          )
      );
  END;
  </code></pre>
  
  <p>I'm not sure about the return type of the function. <code>DBMS_OBFUSCATION_TOOLKIT.VARCHAR2_CHECKSUM</code> looks like the appropriate choice and as far as I can tell it works as expected but the package definition for <code>dbms_obfuscation_toolkit</code> as displayed by SQL Developer shows this:</p>
  
  <pre><code>SUBTYPE varchar2_checksum IS VARCHAR2(16);
  </code></pre>
  
  <p>The output has 32 characters so I must be doing something wrong. My questions:</p>
  
  <ul>
  <li>What's the correct type for the <code>RETURN</code> statement?</li>
  <li>Am I doing unnecessary conversions to calculate the hash?</li>
  </ul>