RTRIM( )

This MySQL function returns the given string with any trailing spaces removed.

Syntax

Below is the syntax for this command. Text within square brackets (i.e, [ and ] ) are optional. Choices are separated by bars (i.e, | ). Ellipses preceded by a comma indicates a repeating pattern. Ellipses before or after syntax are used to highlight a relevant except from the larger syntax. Text displayed in italic letters represent text that should be replaced with the specific names related to the database (e.g., column with the name of the column).

RTRIM(string)

Explanation

This function returns the given string with any trailing spaces removed. When using with an SQL statement like UPDATE, rows that do not contain trailing spaces will not be changed. This function is multi-byte safe. To trim leading spaces, use LTRIM( ); use TRIM( ) to trim both leading and trailing spaces.

Examples

UPDATE students
SET name_last = RTRIM(name_last);

In this example, the last names of several students have been entered inadvertently with a space at the end of the names. This SQL statement removes any trailing spaces from each name retrieved that contains trailing spaces and then writes the trimmed text over the existing data.