Search text containing a new line in MySQL?



You can use REGEXP. Let us first create a table −

mysql> create table DemoTable
(
   Name varchar(100)
);
Query OK, 0 rows affected (1.61 sec)

Insert some records in the table using insert command −

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)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+--------------+
| Name         |
+--------------+
| John Smith   |
| John Doe     |
| David Miller |
| Carol Taylor |
+--------------+
4 rows in set (0.00 sec)

Here is the query to search text containing a new line in MySQL −

mysql> select *from DemoTable where Name regexp "
";

This will produce the following output −

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

Advertisements