UNHEX()
Anonymous contributor
Published Oct 13, 2024
Contribute to Docs
The UNHEX()
function is a build-in function in MySQL that converts a hexadecimal string to its corresponding binary string. Useful when we have data stored in hexadecimal format we can use UNHEX()
function to convert it to the original binary form making it usable and understandable.
Syntax
UNHEX(val);
val
: A hexadecimal string to be converted to its corresponding binary form.
Example
The below example shows how UNHEX()
function works.
CREATE TABLE documents (id INT PRIMARY KEY,content BLOB);INSERT INTO documents (id, content) VALUES (1, UNHEX('636F6465636164656D79'));SELECT HEX(content) AS 'hex-content', CAST(content AS CHAR) AS readable_contentFROM documentsWHERE id = 1;
The output of the above code will be:
hex-content | readable-content |
---|---|
636F6465636164656D79 | codecademy |
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn MySQL on Codecademy
- Skill path
Analyze Data with SQL
Learn to analyze data with SQL and prepare for technical interviews.Includes 9 CoursesWith CertificateBeginner Friendly17 hours - Free course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner Friendly5 hours