TRIM Function - How to use TRIM Function in MySQL

TRIM Function - How to use TRIM Function in MySQL

Trim function in MySQL is used to remove unwanted characters from starting of ending of string. There are different ways to remove the unwanted characters by using Trim. You might only want to remove leading or trailing or both.

TRIM('String Value');
LTRIM('String Value');
RTRIM('String Value')

TRIM function above will remove the leading and trailing spaces from String value. LTrim will only remove blank spaces from starting and RTRIM will remove trailing blank spaces from String value.

Select ' TechBrothersIT ',
trim(' TechBrothersIT '),
ltrim(' TechBrothersIT '),
rtrim(' TechBrothersIT ');

How to use Trim Function in MySQL - MySQL Tutorial

There is another way to write the TRIM syntax, if you want to also remove specific characters from trailing or leading you can do that.


TRIM([{BOTH|LEADING|TRAILING} [string you want to remove]] FROM str);

In below example, we are removing starting and trailing spaces and also in last part, we are removing Trailing IT from string.

Select ' TechBrothersIT ',
trim(both from ' TechBrothersIT '),
TRIM(Leading from ' TechBrothersIT '),
TRIM(Trailing from ' TechBrothersIT '),
TRIM(Trailing 'IT' from ' TechBrothersIT');

How to use TRIM Function in MySQL to remove Leading or Trailing Values from String

1 comment:

  1. Just discovered your blog, and I’m in LOVE with it! Amazing layout an content. Love your style, you rock!! Thanks a million and please carry on the rewarding work. In the law, testimony is a form of indication that is gotten from a spectator who makes a sincere statement or speech of fact. best essay writing service