为此,请使用REGEXP。例如,字符J,A,V和A。让我们首先创建一个表-
mysql> create table DemoTable ( Value varchar(50) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('XYSJGHAKLMVDFFSA'); mysql> insert into DemoTable values('PQRSTJAVAL'); mysql> insert into DemoTable values('SJATUVAK'); mysql> insert into DemoTable values('JSTUVA');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+------------------+ | Value | +------------------+ | XYSJGHAKLMVDFFSA | | PQRSTJAVAL | | SJATUVAK | | JSTUVA | +------------------+ 4 rows in set (0.00 sec)
以下是使用MySQL在字符串中搜索字符的查询-
mysql> select *from DemoTable where Value REGEXP '.*J.*A.*V.*A';
这将产生以下输出-
+------------------+ | Value | +------------------+ | XYSJGHAKLMVDFFSA | | PQRSTJAVAL | | SJATUVAK | +------------------+ 3 rows in set (0.00 sec)