RPAD
Syntax
RPAD(str,len,padstr)
Description
The RPAD function pads the string str on the right side with the string padstr until the total length reaches len.
-
If the length of
stris greater thanlen, the function returns the leftmostlencharacters ofstr. -
If the length of
stris less thanlenand the combined length ofstrandpadstris greater thanlen, the function returns the leftmostlencharacters of the concatenated string. -
If the length of
stris less thanlenand the combined length ofstrandpadstris less thanlen, the function returns the leftmostlencharacters of the concatenated string after appending multiple copies ofpadstrtostruntil the total length is at leastlen.
Examples
SELECT RPAD('hi',5,'?');
+------------------+
| RPAD('hi',5,'?') |
+------------------+
| hi??? |
+------------------+
1 row in set (0.001 sec)
SELECT RPAD('hi',1,'?');
+------------------+
| RPAD('hi',1,'?') |
+------------------+
| h |
+------------------+
1 row in set (0.000 sec)