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
Recommended Posts:
- MySQL | MD5 Function
- MySQL | IF( ) Function
- MySQL | BIN() Function
- MySQL | Group_CONCAT() Function
- MySQL | CAST( ) Function
- MySQL | NULLIF( ) Function
- MySQL | SESSION_USER( ) Function
- MySQL | ISNULL( ) Function
- MySQL | CONNECTION_ID( ) Function
- MySQL | DECODE( ) Function
- MySQL | UNCOMPRESSED_LENGTH( ) Function
- MySQL | ENCODE( ) Function
- MySQL | DES_ENCRYPT ( ) Function
- MySQL | CONVERT( ) Function
- MySQL | LEAD() and LAG() Function
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.


