Để tìm các hàng chứa ký tự xuống dòng (newline, \n) trong cột văn bản, bạn dùng toán tử REGEXP với mẫu '\n'.
Ví dụ minh họa
Tạo bảng:
mysql> create table DemoTable (
Name varchar(100)
);
Chèn dữ liệu (có \n trong chuỗi):
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');
Hiển thị dữ liệu (MySQL hiển thị \n như khoảng trắng hoặc xuống dòng thực):
mysql> select * from DemoTable;
Kết quả:
+--------------+ | Name | +--------------+ | John Smith | | John Doe | | David Miller | | Carol Taylor | +--------------+
Truy vấn REGEXP tìm chứa newline
mysql> select * from DemoTable where Name regexp '\n';
Kết quả (2 hàng chứa \n):
+--------------+ | Name | +--------------+ | John Smith | | David Miller | +--------------+
Giải thích:
REGEXP '\n': Biểu thức chính quy khớp ký tự newline (ASCII 10, LF)- MySQL REGEXP mặc định case-insensitive
- Ký tự \n trong chuỗi literal SQL cần escape đúng cách tùy client
Mở rộng: Tìm cả \r (Carriage Return, ASCII 13): REGEXP '[\r\n]'. Thay thế newline: REPLACE(Name, '\n', ' ').