MySQL RTRIM() Function

In MySQL, the RTRIM() function removes trailing spaces from the specified string and returns the string without trailing spaces.

If you want to remove leading spaces from a string, you can use the LTRIM() or TRIM().

RTRIM() Syntax

Here is the syntax of MySQL RTRIM() function:

RTRIM(str)

Parameters

str
Required. The string to be trimmed.

Return value

The RTRIM() function returns a string with trailing spaces removed.

If the parameter is NULL, the function will return NULL.

RTRIM() Examples

Here are some examples of MySQL RTRIM() function.

SELECT
    RTRIM('   Hello '),
    RTRIM(NULL);
+--------------------+--------------------------+
| RTRIM('   Hello ') | RTRIM(NULL)              |
+--------------------+--------------------------+
| Hello              | NULL                     |
+--------------------+--------------------------+