在 MySQL 中搜索包含新行文字?


可以使用 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)

更新於: 2020 年 7 月 6 日

647 次瀏覽

開啟 職業生涯

完成課程獲得認證

開始
廣告