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.
Recommended Posts:
- PLSQL | RPAD Function
- MySQL | Common MySQL Queries
- MySQL | LEAD() and LAG() Function
- MySQL | BIN() Function
- MySQL | LAST_DAY() Function
- WEEKOFYEAR() Function in MySQL
- MOD() Function in MySQL
- MySQL | Creating stored function
- MySQL | Group_CONCAT() Function
- MySQL | DEFAULT() Function
- MySQL | AES_ENCRYPT ( ) Function
- MySQL | AES_DECRYPT ( ) Function
- MySQL | MD5 Function
- MySQL | COMPRESS( ) Function
- MySQL | PASSWORD Function
- MySQL | OLD_PASSWORD Function
- MySQL | DES_DECRYPT ( ) Function
- MySQL | DES_ENCRYPT ( ) Function
- MySQL | DECODE( ) Function
- MySQL | ENCODE( ) Function
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.

