Tags
MySQL , RPAD
Asked 2 years ago
31 May 2022
Views 635
david

david posted

what is the use of RPAD in MySQL?

what is RPAD in MySQL ? how to use function RPAD in MySQL?
sec8

sec8
answered Jun 4 '22 00:00

RPAD() function pad string at right side in MySQL.
RPAD() function syntax:
RPAD(string.length,padstring)
the first argument is the string that gets padded
the second argument is the number of the length which RPAD() will return
the third argument is the string which gets padded after the string. this argument should be string or charcater
Example :

select RPAD("PAD",4,"DD");//retrun PADD


select RPAD("i love ",10,"u");//retrun i love uuu


if the second argument length is the less than the length of the main string it cut down the string instead of padding at right

select RPAD("i love",3,'u') //i l

so as you can see above query, RPAD("i love",3,'u') return three-character, because the second argument is 3, and thats why it returns 3 characters.
Post Answer