Pages

Custom Search

How to remove Line feed or Carriage return from varchar or nvarchar column in MYSQL?


This is a rarely asked question, however, I just got encountered with this situation. Answer is pretty simple:

select replace(theColumn, char(13) + char(10), '') from yourTable 

This will remove CRLF if both carriage return and line feed is present.

or 

This will return if there is either one of them or both (CRLF).

select replace(replace(theColumn CHAR(13), char(32)), CHAR(10), char(32)) from yourTable
or 
select replace(replace(theColumn CHAR(13), ''), CHAR(10), '')) from yourTable

Here are some terms you may want to remember:

Control character

ValueTab    char(9)

Line feed    
char(10)
Carriage return   char(13)