Db2 – Does DB2 have equivalents for Oracle’s UTL_ENCODE and UTL_RAW modules

db2oracle

I'm looking for something similar to:

utl_smtp.command(conn, utl_encode.base64_encode(utl_raw.cast_to_raw(<username>)));

I couldn't find any reference among the DB2's system-defined modules and I've read that:

after migrating to DB2 there is a little surprise – there is nothing like UTL_RAW and UTL_ENCODE functions

that was written on March 28, 2010.

Considering that DB2's Oracle compatibility has increased with every release from v9, do the newer versions of DB2 provide any equivalents for Oracle's UTL_ENCODE and UTL_RAW?

Best Answer

I believe you are correct. It does not look like DB2 has built in support for base64 encoding.

So that would leave the following as options:

  1. Handle the encoding within your programs.
  2. Write a Java routine (stored procedure) to handle it.
  3. Using a different encryption scheme. DB2 comes with encryption built into itself. There is an ENCRYPT function. Check it out.

Be careful with Java implementations of base64 though. A coworker of mine has mentioned he has seen a bug in all versions of it, in which "words" that have duplicate letters can decrypt into junk. So be careful and double check your base64 encoding/decoding.