34

我执行了以下查询,由于某种原因它没有替换数据库中的换行符。它说 Rows match 1 but no change 。有什么问题?

mysql> UPDATE aboutme SET abouttext=REPLACE(abouttext,'\\n','') WHERE userid='5099a95cd944b8.22468149';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0
4

6 回答 6

49

\n您可以使用, not匹配换行符\\n

代码:

 UPDATE aboutme 
 SET abouttext=REPLACE(abouttext,'\n','') 
 WHERE userid='5099a95cd944b8.22468149';
于 2012-11-07T16:01:01.617 回答
22

如果\n在我的情况下不起作用,则以下工作\r\n

UPDATE aboutme 
SET abouttext=REPLACE(abouttext,'\r\n','') 
WHERE userid='5099a95cd944b8.22468149';

就我而言,它是一个 Web 应用程序。

于 2015-11-20T17:08:13.773 回答
7

你认为它包含\n,但它有\r

update [Table] set [column]=replace(convert([column] using utf8) ,'\r','');

在你的情况下:

update aboutme set abouttext=replace(convert(abouttext using utf8) ,'\r','');
于 2013-09-26T12:42:09.307 回答
0

这就是发生的事情

mysql> mysql> select * from t1 limit 3;
+----------+------------+-----------+---------------------+
| actor_id | first_name | last_name | last_update         |
+----------+------------+-----------+---------------------+
|        1 | PENELOPE   | GUINESS   | 2006-02-15 04:34:33 |
|        2 | NICK       | WAHLBERG  | 2006-02-15 04:34:33 |
|        3 | ED         | CHASE     | 2006-02-15 04:34:33 |
+----------+------------+-----------+---------------------+
3 rows in set (0.00 sec)

mysql> update t1 set first_name=replace(first_name,'abc','') where first_name='ed';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 10  Changed: 0  Warnings: 0

mysql> select * from t1 limit 3;
+----------+------------+-----------+---------------------+
| actor_id | first_name | last_name | last_update         |
+----------+------------+-----------+---------------------+
|        1 | PENELOPE   | GUINESS   | 2006-02-15 04:34:33 |
|        2 | NICK       | WAHLBERG  | 2006-02-15 04:34:33 |
|        3 | ED         | CHASE     | 2006-02-15 04:34:33 |
+----------+------------+-----------+---------------------+
3 rows in set (0.00 sec)


mysql> update t1 set first_name=replace(first_name,'ED','EDD') where first_name='ed';
Query OK, 10 rows affected (0.00 sec)
Rows matched: 10  Changed: 10  Warnings: 0

mysql> select * from t1 limit 3;
+----------+------------+-----------+---------------------+
| actor_id | first_name | last_name | last_update         |
+----------+------------+-----------+---------------------+
|        1 | PENELOPE   | GUINESS   | 2006-02-15 04:34:33 |
|        2 | NICK       | WAHLBERG  | 2006-02-15 04:34:33 |
|        3 | EDD        | CHASE     | 2006-02-15 04:34:33 |
+----------+------------+-----------+---------------------+

3 rows in set (0.00 sec)

我的意思是它工作的 where 条件就是为什么你有“匹配的行:1”但是你的替换找不到\\n替换它,这就是为什么要changed: 0检查你的表数据。

于 2012-11-07T16:09:29.520 回答
0

REPLACE 函数区分大小写,我认为它属于 MySql 服务器版本

description=REPLACE(description, 'Videosite', 'video.5la.net') 与 description=REPLACE(description, 'VideoSite', 'video.5la.net') 的结果不同

于 2018-03-10T08:56:44.827 回答
0

尝试这样的事情:

REPLACE(REPLACE(text, CHAR(92), '#'), '#n', ' ')
于 2021-09-27T13:36:25.610 回答