Open In App

MySQL | BINARY Function

Last Updated : 21 Nov, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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 

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads