Syntax error How can we enter characters as Hexadecimal (HEX) number in MySQL statement?

How can we enter characters as Hexadecimal (HEX) number in MySQL statement?



Following are the two approaches with the help of which we can enter characters as a Hexadecimal number −

By prefix ‘X’

In this approach we need to quote hexadecimal numbers within single quotes with a prefix of X. Then HEX number string will be automatically converted into a character string.

Example

mysql> Select X'5152545678';
+---------------+
| X'5152545678' |
+---------------+
| QRTVx         |
+---------------+
1 row in set (0.00 sec)

By prefix 0x

In this approach, we need to write hexadecimal numbers without any quotes with a prefix of 0x. Then HEX number string will be automatically converted into a character string.

Example

mysql> Select 0x5152545678;
+--------------+
| 0x5152545678 |
+--------------+
| QRTVx        |
+--------------+
1 row in set (0.00 sec)
Updated on: 2020-06-22T12:25:02+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements