使用正则表达式在逗号分隔列表中查找字符串和下一个字符 - MySQL?
mysqlmysqli database
要在逗号分隔列表中搜索,请使用 MySQL find_in_set()。此处不需要为此目的使用正则表达式。语法如下 −
select *from yourTableName where find_in_set(anyValue,yourColumnName);
让我们创建一个表 −
mysql> create table demo17 −> ( −> id int not null auto_increment primary key, −> first_name varchar(50), −> value text −> ); Query OK, 0 rows affected (1.81 sec)
使用 insert 命令向表中插入一些记录 −
mysql> insert into demo17(first_name,value) values('John','50');
Query OK, 1 row affected (0.11 sec)
mysql> insert into demo17(first_name,value) values('David','');
Query OK, 1 row affected (0.13 sec)
mysql> insert into demo17(first_name,value) values('Adam','50,89');
Query OK, 1 row affected (0.14 sec)
mysql> insert into demo17(first_name,value) values('Adam','49,89,43');
Query OK, 1 row affected (0.20 sec)
使用 select 语句显示表中的记录 −
mysql> select *from demo17;
这将产生以下输出 −
+----+------------+----------+ | id | first_name | value | +----+------------+----------+ | 1 | John | 50 | | 2 | David | | | 3 | Adam | 50,89 | | 4 | Adam | 49,89,43 | +----+------------+----------+ 4 rows in set (0.00 sec)
以下是查找字符串和下一个字符的查询 −
mysql> select *from demo17 where find_in_set(50,value);
这将产生以下输出 −
+----+------------+-------+ | id | first_name | value | +----+------------+-------+ | 1 | John | 50 | | 3 | Adam | 50,89 | +----+------------+-------+ 2 rows in set (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

