MySQL removes line breaks and carriage returns from the field

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.