在MySQL中搜索包含换行符的文本?

您可以使用REGEXP。让我们首先创建一个表-

mysql> create table DemoTable
(
   Name varchar(100)
);

使用插入命令在表中插入一些记录-

mysql> insert into DemoTable values('John\nSmith');
mysql> insert into DemoTable values('John Doe');
mysql> insert into DemoTable values('David\nMiller');
mysql> insert into DemoTable values('Carol Taylor');

使用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 "\n";

这将产生以下输出-

+--------------+
| Name         |
+--------------+
| John Smith   |
| David Miller |
+--------------+
2 rows in set (0.41 sec)