Skip to content
SQLSimplified
string

RTRIM()

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

Description

RTRIM strips characters from the end (right) of a string. By default it removes trailing spaces, common when dealing with fixed-width exports or user-entered text that got padded. Pass a second argument to remove specific trailing characters.

Syntax

RTRIM(string)
RTRIM(string, chars)

Parameters

NameDescriptionOptional
stringThe text to trim on the right.No
charsCharacters to remove (default space).Yes

Return Type

Returns a VARCHAR.

Examples

Loading playground environment...
Loading playground environment...

RTRIM vs TRIM

RTRIM only removes from the right; TRIM removes from both ends. Use LTRIM for the left side.

Common Mistakes

  • Expecting both sides trimmed. RTRIM leaves leading spaces; use TRIM for both.
  • Wrong argument order. Characters to remove come second: RTRIM(string, chars).
  • Trimming the middle. It only touches the end; use REPLACE for inside.

See also: LTRIM, TRIM, REPLACE.

Cite this resource

SQLSimplified. "RTRIM() SQL Function". Available at: https://sqlsimplified.online/reference/rtrim