Removes characters from the right side of a string. rtrim('yxTxyomxx', 'xy') → yxTxyom
Usage notes
RTRIM supports only English characters.
Syntax
string rtrim(string <str>[, <trimChars>])
string trim(trailing [<trimChars>] from <str>)Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
str | Yes | STRING | The string from which trailing characters are removed. BIGINT, DECIMAL, DOUBLE, and DATETIME values are implicitly converted to STRING before evaluation. |
trimChars | No | STRING | The characters to remove. RTRIM treats trimChars as a set and removes any combination of its characters from the right side of str. If omitted, trailing spaces are removed. BIGINT, DECIMAL, DOUBLE, and DATETIME values are implicitly converted to STRING before evaluation. |
Return value
Returns a STRING value.
If
strcannot be implicitly converted to STRING, an error is returned.If
strortrimCharsis null, null is returned.
Examples
Example 1: Remove a trailing space.
-- Returns ' yxTxyomxx' (leading space preserved, trailing space removed)
select rtrim(' yxTxyomxx ');
-- Equivalent statement:
select trim(trailing from ' yxTxyomxx ');Example 2: Remove trailing characters from a character set.
-- Returns 'yxTxyom'. All trailing 'x' and 'y' characters are removed.
select rtrim('yxTxyomxx', 'xy');
-- Equivalent statement:
select trim(trailing 'xy' from 'yxTxyomxx');Example 3: Handle null input.
-- Both statements return null.
select rtrim(null);
select trim('yxTxyomxx', null);Related functions
RTRIM is a string function. For more information about string functions, see String functions.