Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need to find and replace \n in a mysql field

Tags:

replace

sql

mysql

i've got data like this:

1 street\n2street\nmycity\nmytown

What i want to do is replace \n with char(10) as i need a real linebreak in the db field.

I've got:

UPDATE data set `value` = REPLACE(`value`,'\n', char(10)) WHERE `key`='shipping_address';

But that is not working.

Can anyone help please?

like image 970
bjohnb Avatar asked Oct 19 '25 04:10

bjohnb


2 Answers

UPDATE data set `value` = REPLACE(`value`,'\\n', CHAR(10)) WHERE `key`='shipping_address';
like image 71
B F Avatar answered Oct 21 '25 20:10

B F


You forgot to escape the \ like this:

UPDATE data set `value` = REPLACE(`value`,'\\n', char(10)) WHERE `key`='shipping_address';
like image 34
aF. Avatar answered Oct 21 '25 18:10

aF.