- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is MySQL HEX() function and how it is different from CONV() function?n
Actually, HEX() function converts the decimal or string value into a hexadecimal value. After conversion MySQL returns a string representation of that hexadecimal value.
Syntax
HEX(Num or Str)
As we know that HEX() function can convert a number or string hence ‘Num’ in the syntax represents the number which is to be converted to hexadecimal and ‘Str’ is a string whose character is to be converted to two hexadecimal digits.
Example
mysql> Select HEX(210); +----------+ | HEX(210) | +----------+ | D2 | +----------+ 1 row in set (0.00 sec)
In the above example, 210 is a decimal number which is converted to a hexadecimal string representation and it is treated as a BIGINT number.
mysql> SELECT HEX('NULL'); +-------------+ | HEX('NULL') | +-------------+ | 4E554C4C | +-------------+ 1 row in set (0.00 sec)
In the above example, ‘NULL’ is a string whose characters are converted to two hexadecimal digits (per character two hexadecimal digits).
Basically, MySQL HEX() function is equivalent to CONV(N,10,16) but the basic difference is that HEX() can convert string character to two hexadecimal digits but CONV() returns 0 on trying to convert string characters into a hexadecimal string. It is demonstrated in the following example −
Example
mysql> Select HEX('N'); +----------+ | HEX('N') | +----------+ | 4E | +----------+ 1 row in set (0.00 sec) mysql> Select CONV('N',10,16); +-----------------+ | CONV('N',10,16) | +-----------------+ | 0 | +-----------------+ 1 row in set (0.00 sec)
- Related Articles
- What is MySQL HEX() function and how it is different from CONV() function?\n
- In MySQL, how FIELD() function is different from FIND_IN_SET() function?
- What happens if a NULL argument is provided in MySQL CONV() function?
- Do we have any lower and upper limit of base in MySQL CONV() function? What happens if out of limit base is provided in CONV() function?
- How MySQL LOCATE() function is different from its synonym functions i.e. POSITION() and INSTR() functions?
- What is MySQL NULL-safe equal operator and how it is different from comparison operator?
- What happens if the value of number ‘N’ in CONV() function is not as per accordance with its base?
- Kazakhstan National Fund – What is it and how does it function?
- What is the purpose of using MySQL CHAR_LENGTH() function? Which function is the synonym of it?
- In MySQL, how CEILING() and FLOOR() functions are different from ROUND() function?
- What is Profit Planning and how is it related to Finance Function?
- What is MySQL ELT() function?
- What is MySQL MAKE_SET() function?
- What is MySQL OCTET_LENGTH() function?
- What is MySQL INTERVAL() function?
- What is Cyber Terrorism? How is it different from Hacktivism?
