×
☰ See All Chapters

MySQL BINARY Function

MySQL BINARY function casts the string following it to a binary string. By default comparison is case insensitive. BINARY function is used for case sensitive column comparison. This causes the comparison to be case sensitive even if the column is not defined as BINARY or BLOB. BINARY also causes trailing spaces to be significant.

MySQL BINARY Function Syntax

SELECT BINARY(VALUE_OF_ANY_DATA_TYPE/ANY_COLUMN_NAME)

 

MySQL BINARY Function Examples

Creating table for demonstrating BINARY Function

CREATE TABLE CONVERSION_FUNCTIONS

(

NUMERIC_VALUE  INTEGER,

STRING         VARCHAR(10 ),

DATE_VALUE     DATE

);

INSERT INTO CONVERSION_FUNCTIONS (NUMERIC_VALUE, STRING, DATE_VALUE) VALUES

(111, 'AAA', '1991-10-10'),

(222, 'BBB', '1990-05-06'),

(333, 'CCC', '1999-06-07'),

(444, 'DDD', '1995-12-18');

Example 1

SELECT NUMERIC_VAL, BINARY(DATE_VAL),BINARY(NUMERIC_STRING_VAL),BINARY(NUMERIC_VAL)

FROM CONVERSION_FUNCTIONS

mysql-binary-funtion-0
 

Example 2

SELECT NUMERIC_VAL, BINARY(DATE_VAL),BINARY(NUMERIC_STRING_VAL),BINARY(456)

FROM CONVERSION_FUNCTIONS

mysql-binary-funtion-1
 

Example 3

SELECT NUMERIC_VAL, BINARY(DATE_VAL),BINARY(NUMERIC_STRING_VAL),BINARY('456ABC@#$')

FROM CONVERSION_FUNCTIONS

mysql-binary-funtion-2
 

All Chapters
Author