totn MariaDB Functions

MariaDB: RPAD Function

This MariaDB tutorial explains how to use the MariaDB RPAD function with syntax and examples.

Description

The MariaDB 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 MariaDB is:

RPAD( string, length, pad_string )

Parameters or Arguments

string
The string to 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 MariaDB:

  • MariaDB 10

Example

Let's look at some MariaDB RPAD function examples and explore how to use the RPAD function in MariaDB.

For example:

SELECT RPAD('TechOnTheNet.com', 20, 'A');
Result: 'TechOnTheNet.comAAAA'

SELECT RPAD('TechOnTheNet.com', 20, 'ABC');
Result: 'TechOnTheNet.comABCA'

SELECT RPAD('TechOnTheNet.com', 21, 'ABC');
Result: 'TechOnTheNet.comABCAB'

SELECT RPAD('TechOnTheNet.com', 4, 'ABC');
Result: 'Tech'

SELECT RPAD('totn', 8, ' ');
Result: 'totn    '

SELECT RPAD('totn', 6, '123');
Result: 'totn12'

SELECT RPAD('totn', 7, '123');
Result: 'totn123'