Joomla Jumpstart

  • Increase font size
  • Default font size
  • Decrease font size

MySQL Query: Finding newlines

E-mail Print PDF
User Rating: / 1
PoorBest 

Finding newline characters can be very useful when data may contain these unwanted characters (especially if the data will be sent into another MySQL statement). Fortunately, searching for them in MySQL is fairly easy. You just need to know what kind of newline characters you're looking to find.

 

Standard / Linux newline characters

To find all of the rows that have newlines, you can simply use the backslash (\) escape character like this:

 

SELECT * FROM articles WHERE content like '%\n%'; 

DOS / Windows newline characters

If your text is stored with DOS/Windows newline characters, use:

 

SELECT * FROM articles WHERE content like '%\r\n%';

These queries can be extremely useful when performing data cleaning on a MySQL table.

Additional sources

 
contraculto Toda la maƱana peleando con una query MySQL y la culpa era de un ejemplo del codex de WordPress. Cuek.
by contraculto. Link: web
Exaspring Turn on MySQL query cache to speed up query performance? http://pr9.in/4d
by Exaspring. Link: ExaSpring Information Services
mysql_projects MYSQL Advanced Query http://bit.ly/bG6PqZ
by mysql_projects. Link: twitterfeed
Lachmans Na een lange tijd weer me 1e MySQL query gerund
by Lachmans. Link: web

Google AdSense