Mariadb Lpad Function

MariaDB: LPAD Function

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

Description

The MariaDB LPAD function returns a string that is left-padded with a specified string to a certain length.

Syntax

The syntax for the LPAD function in MariaDB is:

LPAD( string, length, pad_string )

Parameters or Arguments

string

The string to left-pad.

length

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

pad_string

The specified string to left-pad to string.

Note

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

Applies To

The LPAD function can be used in the following versions of MariaDB:

  • MariaDB 10

Example

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

For example:

SELECT LPAD('AODBA.com', 20, 'A');
Output: 'AAAAAODBA.com'

SELECT LPAD('AODBA.com', 20, 'ABC');
Output: 'ABCAAODBA.com'

SELECT LPAD('AODBA.com', 21, 'ABC');
Output: 'ABCABAODBA.com'

SELECT LPAD('AODBA.com', 4, 'ABC');
Output: 'Tech'

SELECT LPAD('dbd', 8, ' ');
Output: '    dbd'

SELECT LPAD('dbd', 6, '123');
Output: '12dbd'

SELECT LPAD('dbd', 7, '123');
Output: '123dbd'