Beginner

314. RTRIM Function

Learn how to remove unwanted spaces from the end of a string.

📘 Lesson 314 of 728 ⏱ 8 min 🎯 Beginner

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.

SQL
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.

Have you finished this lesson?

Introduction to SQL – All Lessons