TO_HEX function
Converts a numeric value or binary data to its hexadecimal string representation.
Syntax
TO_HEX(expression)
Arguments
expression: An integer type orVARBINARYvalue to convert.
Returns
A VARCHAR containing the hexadecimal representation of the input value.
Examples
-- Example 1: Convert integer to hex > SELECT TO_HEX(255); 'ff' > SELECT TO_HEX(16); '10' > SELECT TO_HEX(256); '100' -- Example 2: Convert zero > SELECT TO_HEX(0); '0' -- Example 3: Convert large numbers > SELECT TO_HEX(1000000); 'f4240' -- Example 4: Convert binary data > SELECT TO_HEX(x'48454C4C4F'); '48454c4c4f' -- Example 5: NULL handling > SELECT TO_HEX(NULL); NULL
See Also
SHA256 function - Compute SHA-256 hash