MySQL - Trim whitespaces & line breaks?

First, is is possible to trim line breaks from fields in my table?
Second, if I use trim, will it remove *all* the whitespace at the end of a field?  In some cases, it looks like the data has multiple spaces at the end, and I want to be certain that I won't have to run TRIM repeatedly?
n00b0101Asked:
Who is Participating?
 
Roger BaklundCommented:
Yes, you can trim line breaks.

No, trim() will not remove all whitespace. It will only remove one type of whitespace at a time: either spaces or line breaks. It also differs between unix newline and windows crlf.

The syntax for trim() is:

TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str), TRIM([remstr  FROM] str)

http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_trim

You can do any of these:

TRIM(TRAILING '\n' from column)  
TRIM(TRAILING '\r\n' from column)
TRIM(TRAILING ' ' from column)

...but you can't do them all in combination, as far as I know. You would have to run them all repeatedly, untill all whitespace is gone. It might be more efficient to use a script.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.