String HEX() function
MySQL HEX(str), HEX(N) Function
Last Updated : 17 Mar 2025
Hex() is a String function of MySQL. This method return in hexadecimal string of given number or String.
In this article, we will elaborate on the concept of the hex(S or N) function in detail with the help of its various examples.
Syntax
Example 1
Explanation: On execution of the query MySQL HEX() function is used to convert the character value 'a' into its hexadecimal representation.
Output: The output of this example is given below.

Example 2
Explanation: On execution of the query MySQL HEX() function is used to convert the character value 'b' into its hexadecimal representation.
Output: The output of this example is given below.

Example 3
Explanation: On execution of the query MySQL HEX() function is used to convert the character value 'c' into its hexadecimal representation.
Output: The output of this example is given below.

Using the MySQL HEX() function in a Table column
The MySQL HEX() function in the table is used to convert the table value into hexadecimal value.
Follow the steps below to perform the MySQL HEX() functionality in a column of the table.
Step 1: First, create a table named EMP_INFO using the CREATE TABLE statement.
Step 2: After that INSERT data into a table using the INSERT TABLE statement.
Step 3: To check the data is inserted into table or not then use the following SELECT statement.
| ID | Name | Department | Salary | Phone |
|---|---|---|---|---|
| 101 | Anjana Gupta | Purchase | 30000.00 | 9878453481 |
| 102 | Priyanka Sharma | Sales | 40000.00 | 8673193472 |
| 103 | Bobby Kapoor | Marketing | 34000.00 | 8154538525 |
| 104 | Alisha Sharma | Finance | 35000.00 | 9378753481 |
| 105 | Eshant Sharma | HR | 40000.00 | 9878253481 |
Example:
Explanation: On execution of the above query, the MySQL HEX() function is used to convert the values of ID column in the Hexadecimal format.
Output: The output of this example is given below.
| ID | Name | Department | Salary | Phone | HID |
|---|---|---|---|---|---|
| 101 | Anjana Gupta | Purchase | 30000.00 | 9878453481 | 65 |
| 102 | Priyanka Sharma | Sales | 40000.00 | 8673193472 | 66 |
| 103 | Bobby Kapoor | Marketing | 34000.00 | 8154538525 | 67 |
| 104 | Alisha Sharma | Finance | 35000.00 | 9378753481 | 68 |
| 105 | Eshant Sharma | HR | 40000.00 | 9878253481 | 69 |
Frequently Asked Questions on the MySQL HEX(str) Function
1. What are the features of the MySQL HEX(str) function?
Answer: The features of the MySQL HEX(str) function are given below.
- It allows us to convert a numeric or string value to its hexadecimal representation.
- It can be used in hashing or encoding operations, where a hexadecimal representation is required.
- It can be used to compare hexadecimal representations of values.
Next TopicMySQL String