×

MySQL RPAD() function

In this context, we will learn how we can use the MySQL RPAD() function with proper syntax and good examples.

Introduction of MySQL RPAD() function

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

Syntax of the MySQL RPAD() function

The syntax of the MySQL RPAD() function is given as follows:

RPAD(str, len, padstr)

Parameters or arguments used in MySQL RPAD() function:

There are three parameters accepted by the RPAD() function in MySQL, which are given as follows:

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 a string.

Len: This is the length of a final string after the right padding.

padstr: String that is to be added to the right side of the Original Str.

Returns:

It will return a new string of length len after padding.

Application used for RPAD() function:

The RPAD() function can be used in the given below MySQL versions.:

  • MySQL 5.7
  • MySQL 5.6
  • MySQL 5.5
  • MySQL 5.1
  • MySQL 5.0
  • MySQL 4.1
  • MySQL 4.0
  • MySQL 3.23

Examples of MySQL RPAD() function:

Now we will look into some MySQL RPAD() function examples and will explore how we can use the RPAD function in MySQL.

Example-1:

In this example, we will Apply the RPAD() function to a string to get a new padded string in MySQL.

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

Output:

RightPaddedString
JAVATPOINT**********
1 row in set (0.00 sec)

Example 2:

In this example, we will Apply the RPAD() function to a string when the original string is larger than the len parameter.

SELECT RPAD("JAVATPOINT", 6, "*") AS RightPaddedString;

Output:

RightPaddedString
JAVATP
1 row in set (0.00 sec)

Example-3:

When we require a new padded string of column data, we can take the help of the RPAD function.

Pupil_IdNameMarks
1Tarun Saha430
2Nilima Mondal425
3Sanya Jain450
4Amit Sharma460

Table – Pupil_Details

SELECT RPAD(Name, 15, "#") AS RightPadPupilName
FROM Pupil_Details;

Output:

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

Application of MySQL RPAD() function:

This function is used to pad or add a string to the right side of the original string.

Summary:

In the above context, we have learned how we can use the RPAD() function in MySQL used to pad or add a string to the right side of the original string.


Related Topics

MySQL HEX() function

In this context, we will learn how we can use the MySQL HEX() function with proper syntax and good examples. Introduction of MySQL HEX() function For returning an equivalent hexadecimal string value...

3 minutes read.

MySQL LOG2() function

In this context, we will learn how we can use the MySQL LOG2() function to calculate the Logarithm of a specific number with base 2 with proper syntax and examples. Introduction...

2 minutes read.

MySQL TAN() Function

Basically, the TAN() function in MySQL is used to give back the tangent of a mentioned number.In any kind of right-angle triangle, the tangent of an angle is the length...

2 minutes read.

MySQL ASIN() Function

In this context we will learn how we can use the ASIN() function in MySQL with proper syntax and good example. Introduction of MySQL ASIN() function The arc sine value of a...

2 minutes read.

MySQL Join

The relational database system needs to interconnect multiple tables with each other. MySQL is a popular and easy data management system to connect multiple tables. The foreign key is used...

5 minutes read.

MySQL INSTR() Function

In this context, we will learn how we can use the MySQL INSTR() function with proper syntax and good examples. Introduction of MySQL INSTR() function This function in MySQL returns the location...

4 minutes read.

MySQL Full text index

Full text index The full-text index in the table isused to search the full text of the data. This index assigns to the table using a "FULLTEXT" keyword. First, the table...

3 minutes read.

MySQL INNER JOIN

MySQL inner join connects two tables by using their common columns. It is the basic join of the MySQL system. It is used to returns only those results from the...

4 minutes read.

Clustered vs Non-Clustered Index

Clustered vs. Non-Clustered Index The difference between clustered and non-clustered index is the most famous question in the database-related interviews. Both indexes have the same physical structure and are stored as...

2 minutes read.

MySQL RPAD() function

In this context, we will learn how we can use the MySQL RPAD() function with proper syntax and good examples. Introduction of MySQL RPAD() function RPAD() function in MySQL is used to...

2 minutes read.

MySQL vs SQL

What is MySQL? The open-source MySQL relational database management system is a vital software component for web-based applications. As the data is saved and sent over the internet, databases and related...

6 minutes read.

MySQL DATE_FORMAT() function

In this context, we will learn how we can use the MySQL DATE_FORMAT() function with proper syntax and good examples. Introduction of MySQL DATE_FORMAT() function DATE_FORMAT() function in MySQL is used to...

3 minutes read.

MySQL IF statement

The IF statement shows the true condition of the control flow function. The first condition is necessary to fulfill the requirement. The other condition is optional in the "IF" statement....

3 minutes read.

MySQL Descending Index

Descending Index It is a type of index that stores key values in descending order. This query improves the performance of an index query. MySQL system displays the index as per...

3 minutes read.

MySQL POWER() function

In this context, we will learn how we can use the MySQL POWER() function with proper syntax and good examples. Introduction of MySQL POWER() function The value of a number raised to...

3 minutes read.

MySQL Table Query

MySQL table query A database stored a lot of data and divided them into different relations known as tables. Each database can contain more than one table. These tables are created...

7 minutes read.

MySQL vs Oracle

What is MySQL? The open-source MySQL relational database management system is a vital software component for web-based applications. As the data is saved and sent over the internet, databases and related...

6 minutes read.

MySQL COALESCE function

This statement displays the first non-null value of the table data. The COALESCE function returns a null value when all values of the table are null or do not find...

3 minutes read.

MySQL Advance function

The advance function operates numerical values, string values, and data types.  The advance function converts, displays, and compares given values as per requirement. Here, you find out database, table, and...

4 minutes read.

MySQL DATEDIFF() function

In this context, we will learn how we can use the MySQL DATEDIFF() function with proper syntax and good examples. Introduction of MySQL DATEDIFF() function DATEDIFF() function in MySQL is used to...

3 minutes read.