Skip to main content

RTRIM function

Removes trailing (right-side) characters from a string.

Syntax

RTRIM(string [, characters])

Arguments

  • string: The string to trim.

  • characters: Optional. A string containing the set of characters to remove. Each character in this string is removed individually from the end, not as a substring. The default is a single white space.

Returns

A VARCHAR with the specified trailing characters removed.

Examples

-- Example 1: Remove trailing spaces (single parameter)
> SELECT RTRIM('   SQL   ');
'   SQL'

-- Example 2: Remove set of characters
> SELECT RTRIM('   SQLacbab', 'abc');
'   SQL'

-- Example 3: Characters are removed individually, not as substring
-- 'abc' means remove any 'a', 'b', or 'c' characters
> SELECT RTRIM('Hellocba', 'abc');
'Hello'

-- Example 4: No matching characters to remove
> SELECT RTRIM('Hello World', 'x');
'Hello World'

See Also