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
| Name | Description | Optional |
|---|---|---|
| string | The text to trim on the right. | No |
| chars | Characters to remove (default space). | Yes |
Return Type
Returns a VARCHAR.
Examples
Employees & Departments
Loading database engine...
Employees & Departments
Loading database engine...
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.
RTRIMleaves leading spaces; useTRIMfor both. - Wrong argument order. Characters to remove come second:
RTRIM(string, chars). - Trimming the middle. It only touches the end; use
REPLACEfor inside.
Related Functions
See also: LTRIM, TRIM, REPLACE.