RPAD

2023-12-25 08:49:42  Updated

Syntax

RPAD(str,len,padstr)

Purpose

RPAD() right-pads the str string with the padstr string to a length of len characters.

  • If the length of str exceeds len, the leftmost len characters of str are returned.

  • If the length of str is less than len but the length of str right-padded with padstr is greater than len, then the leftmost len characters of the string generated after padding are returned.

  • If the length of str is less than len and the length of str right-padded with padstr is still less than len, then str is right-padded with multiple padstr strings until the length is greater than or equal to len, and the leftmost len characters of the string generated after padding are returned.

Examples

obclient> SELECT RPAD('hi',5,'?');
+------------------+
| RPAD('hi',5,'?') |
+------------------+
| hi???            |
+------------------+
1 row in set

obclient> SELECT RPAD('hi',1,'?');
+------------------+
| RPAD('hi',1,'?') |
+------------------+
| h                |
+------------------+
1 row in set

Contact Us