Removes the characters from the right side of a string.
Usage notes
Currently, the RTRIM function supports only English characters.
Syntax
string rtrim(string <str>[, <trimChars>])
string trim(trailing [<trimChars>] from <str>)
Parameters
This function is used to remove the characters from the right side of a string that is specified by str.
If you do not specify trimChars, the spaces on the right side are removed by default.
If you specify trimChars, the substring that consists of one or more characters specified by trimChars is removed from the right side of the string that is specified by str.
str: required. A value of the STRING type. This parameter specifies the string from the right side of which the characters are removed. If the input value is of the BIGINT, DECIMAL, DOUBLE, or DATETIME type, the input value is implicitly converted into a value of the STRING type before calculation.
trimChars: optional. A value of the STRING type. This parameter specifies the characters to be removed. If the input value is of the BIGINT, DECIMAL, DOUBLE, or DATETIME type, the input value is implicitly converted into a value of the STRING type before calculation.
Return value
A value of the STRING type is returned. The return value varies based on the following rules:
If the value of str is not of the STRING type or cannot be implicitly converted into a value of the STRING type, an error is returned.
If the value of str or trimChars is null, null is returned.
Examples:
Example 1: Remove the space from the right side of string
yxTxyomxx
. Sample statement:-- The return value is yxTxyomxx. select rtrim(' yxTxyomxx '); -- The preceding statement is equivalent to the following statement: select trim(trailing from ' yxTxyomxx ');
Example 2: Remove the substring that consists of one or more characters in the
xy
collection from the right side of the stringyxTxyomxx
.-- The return value is yxTxyom. If x or y appears on the right side of a string, it is removed. select rtrim('yxTxyomxx', 'xy'); -- The preceding statement is equivalent to the following statement: select trim(trailing 'xy' from 'yxTxyomxx');
Example 3: The input parameter is set to null. Sample statement:
-- The return value is null. select rtrim(null); select trim('yxTxyomxx', null);
Related functions
RTRIM is a string function. For more information about functions related to string searches and conversion, see String functions.