Updated on 2026-11-06 GMT+08:00

rpad

Right-pads the string str1 to a length of length using the string str2.

Syntax

rpad(string <str1>, int <length>, string <str2>) 

Parameters

Parameter

Mandatory

Type

Description

str1

Yes

STRING

The string to be right-padded.

length

Yes

INT

The target length after right-padding.

str2

Yes

STRING

The string used for padding.

Return Values

Returns a value of type STRING.

  • If length is less than the length of str1, the string is truncated from the left to length characters.
  • If length is 0, an empty string is returned.
  • If any input parameter is NULL, NULL is returned.

Example Code

Returns hi???.

SELECT rpad('hi', 5, '??'); 

Returns h.

SELECT rpad('hi', 1, '??');