binary在select中用來區分大小寫

CREATE TABLE animals (

    id MEDIUMINT NOT NULL AUTO_INCREMENT,

    name CHAR(30) NOT NULL,

    PRIMARY KEY (id)

);

insert into animals values(null,'kitty'),(null,'KITTY'),(null,'hello');


#沒用binary

select id from animals where name like '%it%';

+----+

| id |

+----+

|  1 |

|  2 |

+----+

2 rows in set (0.00 sec)


#用到binary

select id from animals where name like binary '%it%';

+----+

| id |

+----+

|  1 |

+----+

1 row in set (0.03 sec)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章