我执行了以下查询,由于某种原因它没有替换数据库中的换行符。它说 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
\n
您可以使用, not匹配换行符\\n
。
代码:
UPDATE aboutme
SET abouttext=REPLACE(abouttext,'\n','')
WHERE userid='5099a95cd944b8.22468149';
如果\n
在我的情况下不起作用,则以下工作\r\n
UPDATE aboutme
SET abouttext=REPLACE(abouttext,'\r\n','')
WHERE userid='5099a95cd944b8.22468149';
就我而言,它是一个 Web 应用程序。
你认为它包含\n
,但它有\r
。
update [Table] set [column]=replace(convert([column] using utf8) ,'\r','');
在你的情况下:
update aboutme set abouttext=replace(convert(abouttext using utf8) ,'\r','');
这就是发生的事情
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
检查你的表数据。
REPLACE 函数区分大小写,我认为它属于 MySql 服务器版本
description=REPLACE(description, 'Videosite', 'video.5la.net') 与 description=REPLACE(description, 'VideoSite', 'video.5la.net') 的结果不同
尝试这样的事情:
REPLACE(REPLACE(text, CHAR(92), '#'), '#n', ' ')