13 Votes

MySQL: Remove line breaks before CSV export

Tip by Axuter | 2012-02-09 at 16:19

If you want to export the data from a MySQL table to a CSV file, often line breaks are making trouble. Because newlines are interpreted as the end of a row within the CSV file, we can quickly destroy the export data.

UPDATE tab SET col = replace(col, CHAR(13,10), '');

This brief MySQL command brings everything in order. It replaces in the column "col" of the table "tab" all line breaks with nothing, so that in other words, all line breaks will be deleted from this column.

Because under circumstances, with this command, non-contiguous words may be joined (if they were previously only separated with a line break), you can also replace with ' ' alternatively. Sometimes, it would even be a good idea to replace with a wildcard character, so that the line breaks can be restored later.

ReplyPositiveNegative

About the Author

AvatarThe author has not added a profile short description yet.
Show Profile

 

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.