Parsing uses the TRIM function in Mysql syntax to remove two-sided characters _mysql

Source: Internet
Author: User
Tags mysql manual trim

In actual development, you will always encounter this situation


or in this situation.

If you're still using the Select fields from table where you like '/% ' is definitely a thankless practice, then it's definitely a priority to study MySQL's own functions carefully. My first time is to think that the PHP function in the trim is also possible to use in MySQL, the answer is yes. You can find from the MySQL manual, of course, you can Baidu, I said below the same as predecessors.
SELECT *,trim (Leading '/' from ' path ') as paths from ' ts_back_pic ' limit 10
A grand Introduction to the first, leading, you can delete the characters specified on the left and the string

SELECT *,trim (trailing '/' from ' path ') as paths from ' ts_back_pic ' limit 10
Second, you can delete the specified character on the right and the string



SELECT *,trim (BOTH '/' from ' path ') as paths from ' ts_back_pic ' limit 10
Third, you can delete the specified characters on both sides and the string



The most important, and the PHP function is the difference is that trim in the PHP function is to delete more than one character, and in MySQL, but the deletion of the string

Let's have a simple one.
SELECT *,trim (' path ') as paths from ' ts_back_pic ' limit 10;
Remove both sides of a space
It's a complex, complicated type.
SELECT *, trim (BOTH ' \ r \ n ' from trim (' path ')] as paths from ' ts_back_pic ' limit 10;
Environment: A space after a return to a bit, to remove the space + carriage

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.