totn MariaDB Functions

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('TechOnTheNet.com', 20, 'A');
Result: 'AAAATechOnTheNet.com'

SELECT LPAD('TechOnTheNet.com', 20, 'ABC');
Result: 'ABCATechOnTheNet.com'

SELECT LPAD('TechOnTheNet.com', 21, 'ABC');
Result: 'ABCABTechOnTheNet.com'

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

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

SELECT LPAD('totn', 6, '123');
Result: '12totn'

SELECT LPAD('totn', 7, '123');
Result: '123totn'