Categories:
String & Binary Functions (General)

RTRIM

Removes trailing characters, including whitespace, from a string.

See also:LTRIM , TRIM

Syntax

RTRIM(<expr> [, <characters> ])

Arguments

expr
The string expression to be trimmed.
characters

One or more characters to remove from the right side of expr:

The default value is ' ' (a single blank space character), i.e. if no characters are specified, only blank spaces are removed.

Usage Notes

  • The characters in characters can be specified in any order.

  • To remove whitespace, the characters must be explicitly included in the argument. For example, ' $.' removes all leading blank spaces, dollar signs, and periods from the input string.

    Note that this does not remove other whitespace characters (tabulation characters, end-of-line characters, etc.), which also must be explicitly specified.

Collation Details

Collation is supported when the optional second argument is omitted, or when it contains only constant whitespace.

The collation specification of the returned value is the same as the collation specification of the first argument.

Examples

Remove trailing 0 and . characters from a string:

SELECT RTRIM('$125.00', '0.');

------------------------+
 RTRIM('$125.00', '0.') |
------------------------+
 $125                   |
------------------------+

Remove trailing whitespace from a string. This example encloses the strings in > and < characters to help visualize the whitespace:

SELECT CONCAT('>', CONCAT(v, '<')), CONCAT('>', CONCAT(rtrim(v), '<')) FROM tr;

-----------------------------+------------------------------------+
 concat('>', concat(v, '<')) | concat('>', concat(rtrim(v), '<')) |
-----------------------------+------------------------------------+
 >  <                        | ><                                 |
 >  asd  <                   | >  asd<                            |
 >  asd<                     | >  asd<                            |
 >  éché, la lé  <           | >  éché, la lé<                    |
 > <                         | ><                                 |
 ><                          | ><                                 |
 >asd  <                     | >asd<                              |
 [NULL]                      | [NULL]                             |
-----------------------------+------------------------------------+