Member-only story

TRIM() string function in MySQL — with examples.

Josh Otwell
7 min readJun 24, 2020

--

In this post, I’ll cover examples of the MySQL TRIM() function. TRIM() removes specific characters – or spaces – from a given string, at either: the beginning, ending, or potentially in both locations depending on several factors. With an optional keyword argument that controls which character(s) – if any – are removed, TRIM() can be tricky so let’s gain understanding with several easy-to-digest examples…

Photo by Peter Beukema on Unsplash

OS, Software, and DB used:

  • OpenSuse Leap 15.1
  • MySQL 8.0.20

Self-Promotion:

If you enjoy the content written here, by all means, share this blog and your favorite post(s) with others who may benefit from or like it as well. Since coffee is my favorite drink, you can even buy me one if you would like!

TRIM() accepts zero or one of the below keywords along with character(s) to remove, and a target string in which to remove them:

  • LEADING
  • TRAILING
  • BOTH

The given keyword name is relatively self-explanatory and specifies a location within the target string in which characters are removed. Should none of the 3 available location-specific keyword arguments be specified — which is perfectly valid as they are optional — TRIM() works as if the…

--

--

Josh Otwell
Josh Otwell

Written by Josh Otwell

SQL/PHP | Photography | Technical Consultant. Sign-up for my free developer newsletter, OpenLampTech, here: openlamptech.substack.com

No responses yet