joe
joe

Reputation: 35087

How to find the text field data has \n?

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

Upvotes: 0

Views: 1655

Answers (2)

badbod99
badbod99

Reputation: 7526

\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.

Upvotes: 1

soulmerge
soulmerge

Reputation: 75704

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;

Upvotes: 2

Related Questions