I have a a column I want to inspect that contains strings with newlines in them. I want to be able to explicitly see the \n
and \r
characters that are in these strings. Is there some way to write my SQL query to tell it to output the strings with the newlines escaped?
To specify a line break in MySQL, we need the function CHAR(). CHAR() takes an ASCII code and returns the corresponding character. The code for a line break is 10, for a carriage return it is 13. So we can express the following MySQL query for example: UPDATE tab SET col = REPLACE (col, CHAR (13, 10), '' );
If you have spaces between letters then you can use REPLACE() function to remove spaces.
Because MySQL uses C escape syntax in strings (for example, “\n” to represent a newline character), you must double any “\” that you use in LIKE strings. For example, to search for “\n”, specify it as “\\n”.
SELECT REPLACE(
REPLACE(yourcolumn, '\r', '\\r'),
'\n',
'\\n'
) FROM yourtable;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With