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.

Syntax:


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

4 comments:

  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

    ReplyDelete
  2. RBSE 12th Model Paper 2023 Arts, Science & Commerce : There is good news for the students appearing in the 12th Class Board Exam to be conducted by the Rajasthan Board of Secondary Education (RBSE) . Students RBSE 12th Model Paper 2023 can now prepare for the board exam according to the Rajasthan Board 12th Model Paper 2023 Arts, Science & Commerce syllabus . Every year the rbse board releases the Rajasthan board 12th class model Paper 2023 online in pdf on the official website

    ReplyDelete

  3. Excellent effort! It was really awesome and I got a huge knowledge from this blog. Thank you!!!

    Best Family Lawyer for Dads
    Child Support Virginia

    ReplyDelete
  4. Thanks for the post! I really enjoyed reading this blog and It is very interesting. This is clearly a lot to know about this.
    criminal law firm washington DC
    washington dc federal drug crime lawyer

    ReplyDelete