Open In App

RPAD() Function in MySQL

Last Updated : 21 Jun, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

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 padding. 

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_IdNameMarks
1Tarun Saha430
2Nilima Mondal425
3Sanya Jain450
4Amit Sharma460




 

SELECT RPAD(Name, 15, "#") AS RightPadStudentName
FROM Student_Details;



Output : 






















 

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


 


Next Article
Article Tags :

Similar Reads