INARYオペレータは2進性の文字列に続く文字列を送信します。キャラクタ毎よりも、
バイト毎の比較を強制的に行う簡単な方法です。BINARYは後続のスペースにも重要な意味を持たせます。

BINARY strはCAST(str AS BINARY)の略でもあります。


mysql> SELECT 'Hello world!' = 'Hello world!';
+----------------------------------+
| 'Hello world!' = 'Hello world!' |
+----------------------------------+
| 1 |
+----------------------------------+
1 row in set (0.00 sec)

mysql> SELECT 'Hello world!' = BINARY 'Hello world!';
+----------------------------------------+
| 'Hello world!' = BINARY 'Hello world!' |
+----------------------------------------+
| 1 |
+----------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT 'a' = 'a ';
+------------+
| 'a' = 'a ' |
+------------+
| 1 |
+------------+
1 row in set (0.00 sec)

mysql> SELECT 'a' = BINARY 'a ';
+-------------------+
| 'a' = BINARY 'a ' |
+-------------------+
| 0 |
+-------------------+
1 row in set (0.00 sec)

mysql>

binary


mysql> SELECT @var := BINARY 'Lennart';
+--------------------------+
| @var := BINARY 'Lennart' |
+--------------------------+
| Lennart |
+--------------------------+
1 row in set (0.00 sec)

mysql> SELECT @var;
+---------+
| @var |
+---------+
| Lennart |
+---------+
1 row in set (0.00 sec)

mysql> SELECT UPPER(@var);
+-------------+
| UPPER(@var) |
+-------------+
| Lennart |
+-------------+
1 row in set (0.00 sec)

mysql> SELECT UPPER(CONVERT(@var USING utf8));
+---------------------------------+
| UPPER(CONVERT(@var USING utf8)) |
+---------------------------------+
| LENNART |
+---------------------------------+
1 row in set (0.00 sec)

mysql>

binary2

参考サイト
———————————————–
9.5.3. BINARY オペレータ

Comments are closed.

Post Navigation