dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Understanding the TRIM Function in MySQL

In MySQL, the TRIM function has additional implementations other than just trimming spaces. See what else you can do.


advertisement

In MySQL, TRIM has additional implementations other than just trimming spaces. MySQL provided an overloaded version of TRIM function with which you can trim the LEADING, either side (BOTH) and also the TRAILING text.

Let's consider the following to understand how these behave.

Query:

SELECT TRIM(LEADING 'x' FROM 'xxxWHITExxx') AS TEXT;

Output: This will result in the character x being removed from the LEADING end.

+------------+
| TEXT       |
+------------+
| WHITExxx   |
+------------+

Query:

SELECT TRIM(BOTH 'x' FROM 'xxxWHITExxx') AS TEXT;

Output: This will result in the character x being removed from BOTH the ends.

+------------+
| TEXT       |
+------------+
| WHITE      |
+------------+

Query:

SELECT TRIM(TRAILING 'x' FROM 'xxxWHITExxx') AS TEXT;

Output: This will result in the character x being removed from the TRAILING end.

+------------+
| TEXT       |
+------------+
| xxxWHITE   |
+------------+

 

Visit the DevX Tip Bank

 



   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date