MySQL 数据库字段搜索查询的类型?
mysqlmysqli database
以下是语法 −
select *from yourTableName where REGEXP_INSTR(yourColumnName,yourSearchValue);
为了理解上述语法,让我们首先创建一个表 −
mysql> create table demo64 −> ( −> id int not null auto_increment primary key, −> name varchar(40) −> ); Query OK, 0 rows affected (3.06 sec)
使用 insert 命令向表中插入一些记录 −
mysql> insert into demo64(name) values('John Smith'); Query OK, 1 row affected (0.21 sec) mysql> insert into demo64(name) values('John Doe'); Query OK, 1 row affected (0.15 sec) mysql> insert into demo64(name) values('Chris Brown'); Query OK, 1 row affected (0.08 sec) mysql> insert into demo64(name) values('David Miller'); Query OK, 1 row affected (0.20 sec) mysql> insert into demo64(name) values('Carol Taylor'); Query OK, 1 row affected (0.10 sec)
使用 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)