千家信息网

binary在select中用来区分大小写

发表于:2024-10-09 作者:千家信息网编辑
千家信息网最后更新 2024年10月09日,CREATE TABLE animals (id MEDIUMINT NOT NULL AUTO_INCREMENT,name CHAR(30) NOT NULL,PRIMARY KEY (id));
千家信息网最后更新 2024年10月09日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)


0