Updated on 2026-11-06 GMT+08:00

rtrim

The rtrim function is used to remove characters from the right end of str:

  • If trimChars is not specified, space characters are removed by default.
  • If trimChars is specified, the characters in trimChars are treated as a set. The longest possible substring from the right end of str where all characters are in the trimChars set is removed.

Similar functions:

  • ltrim: The ltrim function removes characters from the left end of str.
  • trim: The trim function removes characters from both the left and right ends of str.

Syntax

rtrim([<trimChars>, ]string <str>)

or

rtrim(trailing [] from ) 

Parameters

Parameter

Mandatory

Type

Description

str

Yes

STRING

The string from which to remove characters from the right end. If the input is of type BIGINT, DECIMAL, DOUBLE, or DATETIME, it is implicitly converted to STRING type before evaluation.

trimChars

No

STRING

The characters to be removed.

Return Values

Returns a value of type STRING.

  • If str is not of type STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME, an error is returned.
  • If str or trimChars is NULL, NULL is returned.

Example Code

  • Remove the right spaces from the string yxabcxx . The command example is as follows.

    Returns the string yxabcxx.

    select rtrim('yxabcxx     ');

    Equivalent to the following statement.

    select trim(trailing from ' yxabcxx ');
  • Remove the substring from the right end of yxabcxx where all characters are in the set xy.

    Returns yxabc. Whenever an x or y is encountered at the right end, it is removed.

    select rtrim('xy', 'yxabcxx');

    Equivalent to the following statement.

    select trim(trailing 'xy' from 'yxabcxx');
  • The input parameter is NULL. The command example is as follows.

    Returns NULL.

    select rtrim(null);      select rtrim('yxabcxx', 'null');