All Products
Search
Document Center

MaxCompute:RTRIM

Last Updated:Mar 26, 2026

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

ParameterRequiredTypeDescription
strYesSTRINGThe string from which trailing characters are removed. BIGINT, DECIMAL, DOUBLE, and DATETIME values are implicitly converted to STRING before evaluation.
trimCharsNoSTRINGThe 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 str cannot be implicitly converted to STRING, an error is returned.

  • If str or trimChars is 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.