How to remove line breaks and carriage return characters in the MySQL field :????????? UPDATEtablenameSETfieldREPLACE (REPLACE (field, CHAR (10),), CHAR (13 ),);????????? Char (10 ):? Line Break ????????? Char (13 ):? The MySQL trim function cannot remove carriage return and line feed, but can only remove unnecessary
How to remove line breaks and carriage return characters in the MySQL field :????????? UPDATE tablename SET field = REPLACE (field, CHAR (10), ''), CHAR (13 ),'');????????? Char (10 ):? Line Break ????????? Char (13 ):? The MySQL trim function cannot remove carriage return and line feed, but can only remove unnecessary
MySQL removes line breaks and carriage returns from fields
Solution:
????????? UPDATE tablename SET field = REPLACE (field, CHAR (10), ''), CHAR (13 ),'');
????????? Char (10 ):? Line Break
????????? Char (13 ):? Carriage Return
MySQL trim functions cannot remove carriage return and line breaks. They can only remove unnecessary spaces. You can use the replace function of MySQL to solve this problem. The specific solution is as follows:
Suppose you want to review the database content as "I love you?
"(Note that there is a line break after the content) through (status changed to 1 )?
Is the previous SQL statement ineffective?
UPDATE 'tran '?
SET 'status' = '1 '?
WHERE 'msg '=' I love you ';
The modified statement? UPDATE 'tran '?
SET 'status' = '1 '?
WHERE trim (replace ('msg ',' \ r \ n', '') = 'I love you ';
If you replace the carriage return and line feed in the data with spaces and trim them out, the goal is achieved. Although it is not perfect, it cannot be controlled during user input, fortunately, the efficiency of MySQL built-in functions is quite guaranteed .?
UPDATE 'tran '?
SET 'status' = '1 '?
WHERE trim (?
BOTH '\ r \ n '?
FROM content) = 'Love you'
With two trim functions, the advantage is that it will not replace the line breaks and carriage returns in the middle of the content, but will only handle the spaces at the beginning and end of the line breaks, which is equivalent to the trim function in php.