MySQL: RPAD Function

  • Post author:
  • Post category:MySQL
  • Post comments:1 Comment
MySQL RPAD Function

In this guide, we will explain how to use the MySQL RPAD function with syntax and examples.

Description

The MySQL RPAD function returns a string that is right-padded with a specified string to a certain length.

Syntax

The syntax for the RPAD function in MySQL is:

RPAD( string, length, pad_string )

Parameters or Arguments

string

The string to the right-pad.

length

The length of the result after string has been right-padded.

pad_string

The specified string to right-pad to string.

Note

  • If string is longer than length, the RPAD function will remove characters from string to shorten it to length characters.
  • See also the LPAD function.

Applies To

The RPAD function can be used in the following versions of :

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

Example

Let’s look at some RPAD function examples and explore how to use the RPAD function.

For example:

mysql> SELECT RPAD('adglob.in', 11, 'A');
Result: 'adglob.inAA'

mysql> SELECT RPAD('adglob.in', 12, 'A');
Result: 'adglob.inAAA'

mysql> SELECT RPAD('abc', 6, ' ');
Result: 'abc   '

mysql> SELECT RPAD('abc', 9, 'XYZ');
Result: 'abcXYZXYZ'

mysql> SELECT RPAD('abc', 10, 'XYZ');
Result: 'abcXYZXYZX'

Next Topic : Click Here

This Post Has One Comment

Leave a Reply