您可以将 BINARY 与 LIKE 运算符一起使用。让我们首先创建一个表 -
mysql> create table DemoTable ( Header text );
使用插入命令在表中插入记录 -
mysql> insert into DemoTable values('Programming tutorials on MySQL'); mysql> insert into DemoTable values('programming in Java language'); mysql> insert into DemoTable values('Program in C language'); mysql> insert into DemoTable values('pRograMMing in Python language');
使用 select 语句显示表中的所有记录 -
mysql> select * from DemoTable;
这将产生以下输出 -
+--------------------------------+ | Header | +--------------------------------+ | Programming tutorials on MySQL | | programming in Java language | | Program in C language | | pRograMMing in Python language | +--------------------------------+ 4 rows in set (0.00 sec)
以下是按小写字母搜索单词的查询 -
mysql> select * from DemoTable where binary Header like '%programming%';
这将产生以下输出 -
+------------------------------+ | Header | +------------------------------+ | programming in Java language | +------------------------------+ 1 row in set (0.05 sec)
注意:如果要按大写字母搜索单词,则需要将该单词放入 LIKE 运算符中。