Name

TRIM( )

Synopsis

TRIM([[BOTH | LEADING | TRAILING] [padding] FROM] string)

This function returns the string given with any trailing or leading padding removed, depending on which are specified. The default padding is a space if none is specified.

SELECT TRIM(LEADING '.' FROM col1),
       TRIM(TRAILING FROM col2),
       TRIM(BOTH '-' FROM col3),
       TRIM(col4)
FROM table1;

In this generic example, leading dots will be removed from the output of col1, spaces will be eliminated from col2, leading and trailing hyphens will be removed from col3, and leading and trailing spaces will be removed from col4.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.