dcsimg
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

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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.
Thanks for your registration, follow us on our social networks to keep up-to-date