在MYSql中替换新行字符不起作用

时间:2012-11-07 15:56:54

标签: mysql sql

我执行了以下查询,由于某种原因它没有替换数据库中的新行字符。它表示行匹配1但没有变化。什么可能是错的?

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

5 个答案:

答案 0 :(得分:33)

您可以使用\n匹配换行符,而不是\\n

代码:

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

答案 1 :(得分:12)

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

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

我的案例是网络应用程序。

答案 2 :(得分:3)

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

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

在你的情况下:

update aboutme set abouttext=replace(convert(abouttext using utf8) ,'\r','');

答案 3 :(得分: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)

我的意思是它所处的工作条件就是为什么你有'行匹配:1'但你的替换找不到\\n来代替它,这就是为什么changed: 0所以检查你的表数据

答案 4 :(得分:0)

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

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