×

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 Stored Procedure

MySQL creates the "stored procedure" function to operate database information. You can use parameters, blocks, and statements to create a new procedure. The procedure requires a database table to use...

3 minutes read.

MySQL Composite Index

Composite Index A composite index is an index that is used on multiple columns. MySQL management system manages multiple columns simultaneously. Therefore, the single index contains multiple columns in one query...

3 minutes read.

MySQL RIGHT JOIN

MySQL right join links two tables with each other. The left table column connects with the complete right side table. Each row of the right table tries to connect with...

4 minutes read.

MySQL FORMAT() function

In this context, we will learn how we can use the MySQL FORMAT() function with proper syntax and good examples. Introduction of MySQL FORMAT() function This function in MySQL helps to format...

2 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 FLOOR() function

In this context, we will learn how we can use the MySQL FLOOR() function with proper syntaxes and examples. Introduction of MySQL Floor() function: FLOOR() function in MySQL is used to return...

3 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 Clauses

MySQL Clauses MySQL system clauses are keywords or statements to handle information. It helps to operate a group of the data and apply it to require conditions. The clauses apply conditions...

16 minutes read.

MySQL DATE_ADD() function

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

3 minutes read.

MySQL RIGHT() Function

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

3 minutes read.

MySQL LOG() function

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

3 minutes read.

MySQL SUM function

The SUM() function displays the total addition of the table values. It supports the arithmetic operation of the column values. This function does not return a null value. Here, the...

5 minutes read.

MySQL CONCAT() function

In this context, we will learn how we can use the MySQL CONCAT() function with proper syntax and good examples. Introduction of MySQL CONCAT() function By using the MySQL CONCAT function, we...

3 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 Date and Time function

The date function displays day, year, month, time, and current date. It shows the date and time as per the requirement of the applications. The data either store on the...

8 minutes read.

MySQL COUNT function

The count function returns the number of rows in the table. This function shows either the entire rows count or the required row count of the table. It determines the...

5 minutes read.

MySQL MOD() function

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

3 minutes read.

MySQL UPDATE JOIN

The UPDATE JOIN is a MySQL statement used to perform cross-table updates that means we can update one table using another table with the JOIN clause condition. The "update join"...

5 minutes read.

MySQL ELT() function

In this context, we will learn how we can use the MySQL ELT() function with proper syntax and good examples. Introduction of MySQL ELT() function In the ELT function, the number field...

2 minutes read.

MySQL DELETE JOIN

Sometimes join becomes complicated and unwanted. In such cases, we can delete the unwanted joins in the tables. You can delete inner join, left join, right join as per requirement....

3 minutes read.