views:

42

answers:

2

How to find the text field data has \n in mysql?

for ex :

field :

address  :asfalghaln asdgl sdnslbvaslcbn 

address2 : adsadas
phone :2323

How to find the address has \n or not ? in mysql

+2  A: 

You use a string function to verify the presence of single characters:

SELECT FROM YourTable WHERE LOCATE("\n", textColumn) != 0;

This won't work, if the first character is a newline, though, so you might want to check that too:

SELECT FROM YourTable WHERE LEFT(textColumn, 1) != "\n" AND LOCATE("\n", textColumn) != 0;
soulmerge
+1  A: 

\n is ASCII character 10. You can get the A ASCII char from the char function in mysql.

SELECT char(10)

Instr will give you the position in the string of the \n character

SELECT INSTR('my new
line', char(10));

A value of > 0 will indicate the \n is present (and where it is) a 0 value indicates there is no \n.

badbod99
INSTR is almost the same as LOCATE (arguments are reversed), and you still have the problem with the first character.
soulmerge