LPAD Function

The LPAD function returns a copy of source_string that is left-padded to the total number of characters specified by length.

LPAD Function

1  LPAD ( source_string , length?  , pad_string )
Element Description Restrictions Syntax
length Integer value that specifies total number of characters in the returned string Must be an expression, constant, column, or host variable of a data type that can be converted to an integer data type Literal Number
pad_string String that specifies the pad character or characters Must be an expression, constant, column, or host variable of a data type that can be converted to a character data type Expression
source_string String that serves as input to the LPAD function Must be an expression, constant, column, or host variable of a data type that can be converted to a character data type Expression

Any argument to the LPAD function must be of a built-in data type.

The pad_string parameter specifies the character or characters to be used for padding the source string. The sequence of pad characters occurs as many times as necessary to make the return string the storage length specified by length.

The series of pad characters in pad_string is truncated if it is too long to fit into length. If you specify no pad_string, the default value is a single blank (ASCII 32) character.

The return data type is based on the three arguments, using the return type promotion rules that the section Return Types from the CONCAT Function describes.

In the following example, the user specifies that the source string is to be left-padded to a total length of 16 characters. The user also specifies that the pad characters are a series consisting of a hyphen and an underscore ( -_ ).
SELECT LPAD('Here we are', 16, '-_') FROM mytable;
The following table shows the output of this SELECT statement.
(constant)
-_-_-Here we are