MariaDB: BINARY Function
This MariaDB tutorial explains how to use the MariaDB BINARY function with syntax and examples.
Description
The MariaDB BINARY function converts a value to a binary string.
Syntax
The syntax for the BINARY function in MariaDB is:
BINARY value
Parameters or Arguments
- value
- The value to convert to a binary string.
Note
- The BINARY function is shorthand for CAST(value AS BINARY).
- See also CONVERT function.
Applies To
The BINARY function can be used in the following versions of MariaDB:
- MariaDB 10
Example
Let's look at some MariaDB BINARY function examples and explore how to use the BINARY function in MariaDB.
For example:
SELECT BINARY('TechOnTheNet.com'); Result: 'techonthenet.com' SELECT BINARY('T'); Result: 'T'
Using the BINARY function to cast a value to a binary string is one way to force a byte-by-byte comparison of strings, rather than a character-by-character comparison. Let's investigate this further.
For example:
SELECT 'TECHONTHENET' = 'techonthenet'; Result: 1
If we ran the example above, MariaDB would perform a character-by-character comparison of 'TECHONTHENET' and 'techonthenet' and return 1 (because on a character-by-character basis, 'TECHONTHENET' and 'techonthenet' are equivalent).
However, if we modified the example by adding the BINARY function as follows, changing the comparison to byte-by-byte instead of character-by-character:
SELECT BINARY 'TECHONTHENET' = 'techonthenet'; Result: 0
MariaDB would perform a byte-by-byte comparison of 'TECHONTHENET' and 'techonthenet' and would return 0 (because on a byte-by-byte basis, 'TECHONTHENET' and 'techonthenet' are NOT equivalent.)
Advertisements