在 MySQL 中,删除文本中的 \ 的查询是什么?

mysqlmysqli database更新于 2025/5/23 14:04:17

要从文本中删除
\r,您需要使用 REPLACE 命令。语法如下 −

UPDATE yourTableName SET yourColumnName=REPLACE(yourColumnName,’\r
’,’ ‘);

为了理解上述语法,让我们创建一个表。创建表的查询如下 −

mysql> create table removeDemo
-> (
-> Id int NOT NULL AUTO_INCREMENT,
-> Name text,
-> PRIMARY KEY(Id)
-> );
Query OK, 0 rows affected (0.79 sec)

现在使用 insert 命令在表中插入一些记录。查询如下 −

mysql> insert into removeDemo(Name) values('John\r
SmithCarol'); Query OK, 1 row affected (0.13 sec) mysql> insert into removeDemo(Name) values('LarryMike\r
Sam'); Query OK, 1 row affected (0.34 sec) mysql> insert into removeDemo(Name) values('David\r
BobJames'); Query OK, 1 row affected (0.10 sec)

使用 select 语句显示表中的所有记录。查询如下 −

mysql> select *from removeDemo;

以下是包含 \r
格式的输出,因此输出格式看起来不正确 −

+----+------------------+
| Id | Name             |
+----+------------------+
| 1  | John SmithCarol  |
| 2  | LarryMike Sam    |
| 3  | David BobJames   |
+----+------------------+
3 rows in set (0.00 sec)

以下是从文本中删除 \r
的查询 −

mysql> update removeDemo set Name=replace(Name,'\r
',''); Query OK, 3 rows affected (0.12 sec) 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)

相关文章


有用资源