MySQL | BINARY Function

The MySQL BINARY function is used for converting a value to a binary string. The BINARY function can also be implemented using CAST function as CAST(value AS BINARY).
The BINARY function accepts one parameter which is the value to be converted and returns a binary string.

Syntax:

BINARY value

Parameters Used:

  • value – It is used to specify the value to be converted.

Return Value:
The MySQL BINARY function returns a binary string after converting a value specified by the user.

Supported Versions of MySQL:



  • MySQL 5.7
  • MySQL 5.6
  • MySQL 5.5
  • MySQL 5.1
  • MySQL 5.0
  • MySQL 4.1
  • MySQL 4.0
  • MySQL 3.23

Example-1: Implementing BINARY function to return a binary string.

SELECT BINARY('Geeksforgeeks');  

Output:

Geeksforgeeks 

Example-2: Character-by-character comparison of two string without using BINARY function.

SELECT 'GEEKSFORGEEKS' = 'geeksforgeeks'; 

Output:

1 

Example-3: Byte-by-Byte comparison of two string using BINARY function.

SELECT BINARY 'GEEKSFORGEEKS' = 'geeksforgeeks'; 

Output:

0 

Example-4: Byte-by-Byte comparison of two string using BINARY function.

SELECT BINARY 'GEEKSFORGEEKS' = 'GEEKSFORGEEKS'; 

Output:

1 
My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.