对于字符串匹配,请使用LIKE运算符。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> MonthName varchar(100) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('JFMA'); mysql> insert into DemoTable values('JMA'); mysql> insert into DemoTable values('JDN'); mysql> insert into DemoTable values('JFOSA');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+-----------+ | MonthName | +-----------+ | JFMA | | JMA | | JDN | | JFOSA | +-----------+ 4 rows in set (0.00 sec)
以下是在MySQL中执行字符串匹配的查询-
mysql> select *from DemoTable WHERE MonthName LIKE '%J%M%';
输出结果
+-----------+ | MonthName | +-----------+ | JFMA | | JMA | +-----------+ 2 rows in set (0.00 sec)