Alex Rivera | Logout

Does the MySQL TRIM function not trim line breaks or carriage returns?

Asked 2008-11-11T18:17:26.043
32

From my experiments, it does not appear to do so. If this is indeed true, what is the best method for removing line breaks? I'm currently experimenting with the parameters that TRIM accepts of the character to remove, starting with trimming \n and \r.

Edit
Report

2 Answers

8

select trim(both '\r\n' from FIELDNAME) from TABLE; should work if select trim(both '\n' from FIELDNAME) from TABLE; doesn't work.

answered 2009-01-13T14:47:56.080
0

I faced the same issue with one of the fields. There is no perfect solution. In my case i was lucky that the length of the field was supposed to be 6. So i used a query like

update events set eventuniqueid = substring(eventuniqueid, 1, 6) where length(eventuniqueid) = 7;

You will just have to choose the best option based on your need. The replace '\n' and '\r\n' did not work for me and just ended up wasting my time.

answered 2010-10-11T23:39:28.650

Your Answer