How to Compute the Oracle SQL_ID

The Oracle SQL_ID is computed using the following algorithm

  1. append a 0x00 byte to the native SQL query
  2. compute the MD5 hash (it’s unclear whether UTF-8 or the database encoding should be used)
  3. create a 64 bit long value out last two 32 integer values of the hash using big endian order
  4. convert to Base32, 5 bits at a time starting with the most significant bit, using the alphabet 0123456789abcdfghjkmnpqrstuvwxyz

The native SQL query can be accessed in Java either using Connection#nativeSQL or using OracleDatabaseException#getSql.

For a Java implementation check out marschall/sqlid