RPAD() Function in MySQL

RPAD() function in MySQL is used to pad or add a string to the right side of the original string.

Syntax :

RPAD(str, len, padstr)

Parameter : This function accepts three parameter as mentioned above and described below :

  • str : The actual string which is to be padded. If the length of the original string is larger than the len parameter, this function removes the overfloating characters from string.
  • len : This is the length of a final string after the right padding.
  • padstr : String that to be added to the right side of the Original Str.

Returns : It returns a new string of length len after pading.

Example-1 : Applying RPAD() Function to a string to get a new padded string.



SELECT RPAD("geeksforgeeks", 20, "*") AS RightPaddedString;

Output :

RightPaddedString
geeksforgeeks*******

Example-2 : Applying RPAD() Function to a string when the original string is larger than the len parameter.

SELECT RPAD("geeksforgeeks", 10, "*") AS RightPaddedString;

Output :

RightPaddedString
geeksforge

Example-3 : Applying RPAD() Function to a string column in a table :

Table – Student_Details :

Student_Id Name Marks
1 Tarun Saha 430
2 Nilima Mondal 425
3 Sanya Jain 450
4 Amit Sharma 460
SELECT RPAD(Name, 15, "#") AS RightPadStudentName
FROM Student_Details;

Output :

RightPadStudentName
Tarun Saha#####
Nilima Mondal##
Sanya Jain#####
Amit Sharma####

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.