Beginner

320. RPAD Function

Learn how to add characters to the end of a string until it reaches a specified length.

📘 Lesson 320 of 728 ⏱ 9 min 🎯 Intermediate

RPAD pads the end of a string with a specified character or sequence until the requested length is reached.

Fixed-width data formats and structured exports sometimes require text values to have consistent lengths.

Pad department codes with spaces to create a fixed-width value.

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

RPAD is useful for fixed-width files, formatted exports, labels, and legacy system integrations.

  • RPAD adds characters to the end.
  • A target length is specified.
  • It supports fixed-width formatting.
  • It is useful in data exports.
  • Function availability varies by database.
What does RPAD do?

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

Where can RPAD be useful?

RPAD can be useful when preparing fixed-width exports or formatting text for legacy systems.

Have you finished this lesson?

Introduction to SQL – All Lessons