The RTRIM function removes trailing spaces, and in some database systems specified trailing characters, from a string.
Trailing spaces can create inconsistencies in imported data and cause unexpected comparison results.
Remove trailing spaces from department names.
SELECT
RTRIM(Department) AS CleanDepartment
FROM Employees;
RTRIM is useful for cleaning fixed-width files, imported text, and database fields containing unwanted trailing spaces.
- RTRIM removes trailing spaces.
- It cleans the end of a string.
- It is useful for imported data.
- It can improve comparisons.
- Exact behavior varies between databases.
What does RTRIM do?
RTRIM removes unwanted trailing spaces from a string.
Why remove trailing spaces?
Trailing spaces can cause inconsistent text comparisons and affect data-quality checks.