{ “title”: “TO_HEX”, “language”: “en”, “description”: “Convert the input string into the corresponding byte sequence in hexadecimal.” }

Description

Convert the input string into the corresponding byte sequence in hexadecimal.

Alias

TO_BINARY

Syntax

TO_HEX(<str>)

Parameters

ParameterDescription
<str>The string data to be converted

Return Value

Return the decoded VARBINARY (displayed in hexadecimal format with a 0x prefix). Return NULL if any of the following conditions are met: The input is NULL; The input length is 0; The input length is odd; The input contains characters other than [0-9a-fA-F]; The length of the decoded result is 0 (decoding failed).

Examples

select to_hex(NULL),to_hex('a');
+----------------------------+--------------------------+
| to_hex(NULL)               | to_hex('a')              |
+----------------------------+--------------------------+
| NULL                       | NULL                     |
+----------------------------+--------------------------+
select to_hex('ab');
+----------------------------+
| to_hex('ab')               |
+----------------------------+
| 0xAB                       |
+----------------------------+
select to_hex('000A');
+--------------------------------+
| to_hex('000A')                 |
+--------------------------------+
| 0x000A                         |
+--------------------------------+