Beginner

232. RTRIM Function

Learn how to remove unwanted spaces from the end of text values.

📘 Lesson 232 of 728 ⏱ 8 min 🎯 Beginner

The RTRIM function removes trailing spaces from a text value. The exact behavior can vary between database systems.

Trailing spaces can cause inconsistent text values and unexpected comparison or matching results.

Remove unwanted spaces after customer names.

SQL
SELECT
    RTRIM(CustomerName) AS CleanName
FROM Customers;

RTRIM is useful for data cleansing, imported data, migration processes, and text standardization.

  • RTRIM removes trailing spaces.
  • It is useful for cleaning text.
  • It can improve data matching.
  • Database behavior can vary.
  • TRIM can often remove spaces from both sides.
What does RTRIM do?

RTRIM removes trailing spaces from a text value.

What is the difference between LTRIM and RTRIM?

LTRIM removes leading spaces, while RTRIM removes trailing spaces.

Have you finished this lesson?

Introduction to SQL – All Lessons