要从文本中删除\ n \ r,您需要使用REPLACE命令。语法如下-
UPDATE yourTableName SET yourColumnName=REPLACE(yourColumnName,’\r\n’,’ ‘);
为了理解上述语法,让我们创建一个表。创建表的查询如下-
mysql> create table removeDemo -> ( -> Id int NOT NULL AUTO_INCREMENT, -> Name text, -> PRIMARY KEY(Id) -> );
现在,使用insert命令在表中插入一些记录。查询如下-
mysql> insert into removeDemo(Name) values('John\r\nSmithCarol'); mysql> insert into removeDemo(Name) values('LarryMike\r\nSam'); mysql> insert into removeDemo(Name) values('David\r\nBobJames');
使用select语句显示表中的所有记录。查询如下-
mysql> select *from removeDemo;
以下是包含\ r \ n的格式的输出,因此输出的格式不正确-
+----+------------------+ | Id | Name | +----+------------------+ | 1 | John SmithCarol | | 2 | LarryMike Sam | | 3 | David BobJames | +----+------------------+ 3 rows in set (0.00 sec)
这是从文本中删除\ r \ n的查询-
mysql> update removeDemo set Name=replace(Name,'\r\n',''); Rows matched: 3 Changed: 3 Warnings: 0
现在再次检查表记录。查询如下-
mysql> select *from removeDemo;
以下是输出-
+----+----------------+ | Id | Name | +----+----------------+ | 1 | JohnSmithCarol | | 2 | LarryMikeSam | | 3 | DavidBobJames | +----+----------------+ 3 rows in set (0.00 sec)