Parsing using the trim function in MYSQL syntax to delete characters on both sides

Source: Internet
Author: User
Tags mysql manual

In actual development, you always encounter this situation.


Or in this case

If you are still using select fields from table where like '/%', it is definitely a thankless practice, taking a closer look at the built-in functions of MYSQL is definitely the first priority. I first thought that the trim in the PHP function may also be used in mysql. The answer is yes. You can find it in the MYSQL manual. Of course, you can refer to Baidu. What I am talking about below is the same as that of my predecessors.
SELECT *, trim (LEADING '/' FROM 'path') as paths FROM 'ts _ back_pic 'limit 10
We will introduce the first LEADING, which can delete the specified characters and strings on the left.

SELECT *, trim (TRAILING '/' FROM 'path') as paths FROM 'ts _ back_pic 'limit 10
Second, you can delete the specified character and string on the right.



SELECT *, trim (BOTH '/' FROM 'path') as paths FROM 'ts _ back_pic 'limit 10
Third, you can delete specified characters and strings on both sides.



Most importantly, trim deletes multiple characters in the PHP function, but in MYSQL, it deletes strings.

To make it simple
SELECT *, trim ('path') as paths FROM 'ts _ back_pic 'limit 10;
Delete spaces on both sides
To provide a comprehensive feature
SELECT *, trim (BOTH '\ r \ n' FROM trim ('path') as paths FROM 'ts _ back_pic' limit 10;
Environment: Press enter after a space. You need to delete the space + press Enter.

Related Article

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.