MySQL RPAD() Function
In MySQL, the RPAD()
function right pads a string with a string to the specified length. If you want to left pad a string, use the LPAD()
function.
RPAD()
Syntax
Here is the syntax of MySQL RPAD()
function:
RPAD(str, len, padstr)
Parameters
str
- Required. the string to pad out.
len
- Required. The length to pad to.
padstr
- Optional. The string to pad with.
Return value
The RPAD()
function right pads a string with a string to the specified length and returns the right padded string.
- If
len
less than the length ofstr
,str
will be truncated to the lengthlen
. - If
len
is negative, the function will returnNULL
. - The function will return
NULL
if either parameter isNULL
.
RPAD()
Examples
Here are some examples of MySQL RPAD()
function.
SELECT
RPAD('oh', 10, 'h'),
RPAD('oh', 1, 'h'),
RPAD('oh', -1, 'h'),
RPAD('Hello', 13, 'World'),
RPAD('Hello', 13, NULL)\G
RPAD('oh', 10, 'h'): ohhhhhhhhh
RPAD('oh', 1, 'h'): o
RPAD('oh', -1, 'h'): NULL
RPAD('Hello', 13, 'World'): HelloWorldWor
RPAD('Hello', 13, NULL): NULL