RAWTOHEX scalar function

The RAWTOHEX function returns a hexadecimal representation of a value as a character string.

Read syntax diagramSkip visual syntax diagramRAWTOHEX(expression )

The schema is SYSIBM.

expression
An expression that specifies the string for which the hexadecimal value is to be returned. The expression must return a built-in character string, graphic string, binary string, numeric value, or datetime value. If the value is not a character, graphic, or, binary string, it is implicitly cast to VARCHAR before the function is evaluated.

Result

The result of the function is VARCHAR. If the argument can be null, the result can be null. If the argument is null, the result is the null value. The length of the result is computed based on the following table:

Table 1. Data type of the result as a function of the data types of the argument data type and the length attribute
Argument data type1 Length attribute2 Result data type
CHAR(A) or BINARY(A) A<128 CHAR(A*2)
CHAR(A) or BINARY(A) A>127 VARCHAR(A*2)
VARCHAR(A), VARBINARY(A), CLOB(A), or BLOB(A) A<16337 VARCHAR(A*2)
GRAPHIC(A) A<64 CHAR(A*2*2)
GRAPHIC(A) A>63 VARCHAR(A*2*2)
VARGRAPHIC(A) or DBCLOB(A) A<8169 VARCHAR(A*2*2)
CHAR(A CODEUNITS32) A<64 VARCHAR(A*4*2)
VARCHAR(A CODEUNITS32) or CLOB(A CODEUNITS32) A<4085 VARCHAR(A*4*2)
GRAPHIC(A CODEUNITS32) A<64 VARCHAR(A*2*2*2)
VARGRAPHIC(A CODEUNITS32) or DBCLOB(A CODEUNITS32) A<4085 VARCHAR(A*2*2*2)
1. If string units are not specified, then the string units for the data type are not CODEUNITS32.
2. The maximum length attributes reflect a data type limit or the limit of 16336 bytes for the input argument.

Example

values rawtohex('hello')
	returns 68656C6C6F