Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REPLACE new line character in MYSql not working

Tags:

sql

mysql

I executed following query and for some reason its not replacing new line character in database . It says Rows matched 1 but no change . What can be wrong ?

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 
like image 545
Pit Digger Avatar asked Nov 07 '12 15:11

Pit Digger


People also ask

How do you change a new line character in MySQL?

The Trim() function is used to remove new line characters from data rows in MySQL.

How do I find a new line character in MySQL?

SELECT * FROM mytable WHERE mycolumn REGEXP "\r\n"; Hi Tim, thanks for answering!

How do I add a new line in MySQL?

-- Using both \r\n SELECT 'First line. \r\nSecond Line. ' AS 'New Line'; -- Using both \n SELECT 'First line.

How replace enter with space in MySQL query?

In this case, we use replace function along with string to replace with, which in our case is an empty string. function removeLineBreaks(str) { return str. replace( /[\r\n]+/gm, "" ); } removeLineBreaks("Hello,\n Good Afternoon.


2 Answers

You can match a newline character using \n, not \\n.

Code:

 UPDATE aboutme   SET abouttext=REPLACE(abouttext,'\n','')   WHERE userid='5099a95cd944b8.22468149'; 
like image 171
Ryan Avatar answered Sep 17 '22 17:09

Ryan


If \n does not work as in my case, the following worked \r\n

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

In my case it has been a web application.

like image 25
Hammad Khan Avatar answered Sep 20 '22 17:09

Hammad Khan