Skip to content
Related Articles

Related Articles

MySQL | BINARY Function
  • Last Updated : 21 Nov, 2019
GeeksforGeeks - Summer Carnival Banner

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 

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :