HEX

The HEX function returns a hexadecimal representation of a value.

Read syntax diagram
>>-HEX(expression)---------------------------------------------><

The schema is SYSIBM.

The argument must an expression that returns a value of any built-in data type that is not XML. A character or binary string must not have a maximum length greater than 16352. A graphic string must not have a maximum length greater than 8176.

The result of the function is a character string.

The result can be null; if the argument is null, the result is the null value.

The result is a string of hexadecimal digits. The first two represent the first byte of the argument, the next two represent the second byte of the argument, and so forth. If the argument is a datetime value, the result is the hexadecimal representation of the internal form of the argument.

If the argument is a fixed-length string and the length of the result is less than 255, the result is a fixed-length string. Otherwise, the result is a varying-length string with a length attribute that depends on the following considerations:

  • If the argument is not a varying-length string, the length attribute of the result string is the same as the length of the result.
  • If the argument is a varying-length character or binary string, the length attribute of the result string is twice the length attribute of the argument.
  • If the argument is a varying-length graphic string, the length attribute of the result string is four times the length attribute of the argument.

If expression returns string data, the CCSID of the result is the SBCS CCSID that corresponds to the CCSID of expression. Otherwise, the CCSID of the result is determined from the context in which the function was invoked. For more information, see Determining the encoding scheme and CCSID of a string.

If the argument is a graphic string, the length of the result is four times the maximum length of the argument. Otherwise, the length of the result is twice the (maximum) length of the argument.

Example: Return the hexadecimal representation of START_RBA in the SYSIBM.SYSCOPY catalog table.
   SELECT HEX(START_RBA) FROM SYSIBM.SYSCOPY;