BINARY
This page is part of MariaDB's Documentation.
The parent of this page is: SQL Operators for MariaDB Xpand
Topics on this page:
Overview
Casts strings to binary values.
USAGE
BINARY string
Value Name | Description |
---|---|
| A string expression |
DETAILS
The BINARY
operator converts a string data type into a binary data type.
One common reason for such a conversion is to compare character values with uppercase and lowercase letters not being treated as equal.
EXAMPLES
SELECT 'foo' = BINARY 'FOO';
+----------------------+
| 'foo' = BINARY 'FOO' |
+----------------------+
| 0 |
+----------------------+
SELECT 'foo' = CAST(BINARY 'FOO' AS CHAR);
+------------------------------------+
| 'foo' = CAST(BINARY 'FOO' AS CHAR) |
+------------------------------------+
| 1 |
+------------------------------------+
CREATE TABLE binary_example (
word varchar(32)
);
INSERT INTO binary_example VALUES
('Adjust'), ('adjust'),
('about'), ('About'),
('ABC'), ('abc');
SELECT word
FROM binary_example
ORDER BY BINARY word;
+--------+
| word |
+--------+
| ABC |
| About |
| Adjust |
| abc |
| about |
| adjust |
+--------+
SELECT word
FROM binary_example
ORDER BY word;
+--------+
| word |
+--------+
| ABC |
| abc |
| about |
| About |
| Adjust |
| adjust |
+--------+