Beginner

239. RPAD Function

Learn how to add characters to the right side of a string until it reaches a desired length.

📘 Lesson 239 of 728 ⏱ 9 min 🎯 Intermediate

The RPAD function pads a string on the right with specified characters until the resulting string reaches a requested length.

Right padding is useful when generating fixed-width text formats and structured exports.

Pad a department code with spaces to create a fixed-width field.

SQL
SELECT
    RPAD(DepartmentCode, 10, ' ') AS FixedWidthCode
FROM Departments;

RPAD is useful for fixed-width reports, file exports, text formatting, and legacy system integrations.

  • RPAD adds characters to the right.
  • A target length is specified.
  • A padding character can be provided.
  • It is useful for fixed-width formats.
  • Support varies between database systems.
What does RPAD do?

RPAD adds characters to the right of a string until it reaches the specified length.

Where can RPAD be useful?

It can be useful for fixed-width reports, text files, and legacy system integrations.

Have you finished this lesson?

Introduction to SQL – All Lessons