如何在 MySQL 中按大写或小写字母搜索单词?
您可以在 LIKE 运算符中使用 BINARY。我们首先创建一个表格 –
mysql> create table DemoTable ( Header text ); Query OK, 0 rows affected (1.09 sec)
使用 insert 命令在表格中插入记录 –
mysql> insert into DemoTable values('Programming tutorials on MySQL'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('programming in Java language'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Program in C language'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('pRograMMing in Python language'); Query OK, 1 row affected (0.41 sec)
使用 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 运算符中添加单词。
广告