Mega Code Archive

 
Categories / MySQL Tutorial / Cast Functions Operators
 

BINARY casts the string to a binary string

BINARY causes the comparison to be case sensitive. BINARY also causes trailing spaces to be significant. BINARY str is shorthand for CAST(str AS BINARY). mysql> mysql> SELECT 'a' = 'A'; +-----------+ | 'a' = 'A' | +-----------+ |         1 | +-----------+ 1 row in set (0.00 sec) mysql> SELECT BINARY 'a' = 'A'; +------------------+ | BINARY 'a' = 'A' | +------------------+ |                0 | +------------------+ 1 row in set (0.00 sec) mysql> SELECT 'a' = 'a '; +------------+ | 'a' = 'a ' | +------------+ |          1 | +------------+ 1 row in set (0.00 sec) mysql> SELECT BINARY 'a' = 'a '; +-------------------+ | BINARY 'a' = 'a ' | +-------------------+ |                 0 | +-------------------+ 1 row in set (0.00 sec) mysql>