在 MySQL 中搜索包含换行符的文本?
mysqlmysqli database更新于 2025/7/14 0:44:17
您可以使用 REGEXP。让我们首先创建一个表 −
mysql> create table DemoTable ( Name varchar(100) ); Query OK, 0 rows affected (1.61 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable values('John
Smith');
Query OK, 1 row affected (0.73 sec)
mysql> insert into DemoTable values('John Doe');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable values('David
Miller');
Query OK, 1 row affected (0.24 sec)
mysql> insert into DemoTable values('Carol Taylor');
Query OK, 1 row affected (0.27 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable;
这将产生以下输出 −
+--------------+ | Name | +--------------+ | John Smith | | John Doe | | David Miller | | Carol Taylor | +--------------+ 4 rows in set (0.00 sec)
这是在 MySQL 中搜索包含换行符的文本的查询 −
mysql> select *from DemoTable where Name regexp "
";
这将产生以下输出 −
+--------------+ | Name | +--------------+ | John Smith | | David Miller | +--------------+ 2 rows in set (0.41 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

