Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding a line break in a text string in a SQL table?

I was trying to find line breaks and carriage returns in a column in a SQL table and I am not sure about the syntax.

I tried:

SELECT foo FROM test WHERE foo LIKE CHAR(10) 

I didn't get any results even though I know that the table should return results. What am I doing wrong?

like image 664
user1542296 Avatar asked Oct 25 '12 18:10

user1542296


People also ask

How do I find carriage return and line feed in SQL?

Using SQL to remove a line feed or carriage return means using the CHAR function. A line feed is CHAR(10); a carriage return is CHAR(13).


1 Answers

SELECT foo FROM test WHERE foo LIKE '%' + CHAR(10) + '%' 

Edit: to find all various types of line endings you should probably just check both:

SELECT foo FROM test WHERE foo LIKE '%' + CHAR(10) + '%'                         OR foo LIKE '%' + CHAR(13) + '%' 
like image 152
Chad Avatar answered Sep 29 '22 12:09

Chad