以下是语法-
select *from yourTableName where REGEXP_INSTR(yourColumnName,yourSearchValue);
要了解上述语法,让我们首先创建一个表-
mysql> create table demo64 −> ( −> id int not null auto_increment primary key, −> name varchar(40) −> );
借助insert命令将一些记录插入表中-
mysql> insert into demo64(name) values('John Smith'); mysql> insert into demo64(name) values('John Doe'); mysql> insert into demo64(name) values('Chris Brown'); mysql> insert into demo64(name) values('David Miller'); mysql> insert into demo64(name) values('Carol Taylor');
使用select语句显示表中的记录-
mysql> select *from demo64;
这将产生以下输出-
+----+--------------+ | id | name | +----+--------------+ | 1 | John Smith | | 2 | John Doe | | 3 | Chris Brown | | 4 | David Miller | | 5 | Carol Taylor | +----+--------------+ 5 rows in set (0.00 sec)
以下是字段类型搜索查询的查询-
mysql> select *from demo64 where REGEXP_INSTR(name,'John');
这将产生以下输出-
+----+------------+ | id | name | +----+------------+ | 1 | John Smith | | 2 | John Doe | +----+------------+ 2 rows in set (0.00 sec)