Home

Lpad

Lpad is a string manipulation function used to pad the left side of a text string with a specified padding string until a desired total length is reached. It is commonly employed to align output in fixed-width formats, format numbers as identifiers, or prepare values for data export. The operation typically involves providing the source string, the target length, and an optional padding string (which may default to a single space in some implementations). If the source string is longer than the target length, the result is usually truncated to the requested length.

In mainstream SQL dialects, Lpad generally follows a pattern such as LPAD(string, length, pad_string). The padding

Common implementations:

- Oracle: LPAD(string, length, pad_string)

- MySQL: LPAD(str, length, padstr)

- PostgreSQL: LPAD(string, length, pad_string)

- SQL Server: There is no built-in LPAD function; a typical workaround uses REPLICATE combined with LEFT

Examples:

- LPAD('cat', 5, 'x') yields 'xxcat'

- LPAD('123', 6, '0') yields '000123'

Notes:

- If the target length is less than the input length, results are often truncated to the

- Some systems count length in characters, other systems in bytes, which can affect results with multibyte

See also: RPAD, textual padding, fixed-width formatting.

string
is
repeated
on
the
left
as
needed
to
reach
the
target
length.
Padding
behavior
for
multi-byte
characters
and
for
varying
pad_string
lengths
can
differ
by
system.
or
RIGHT
to
achieve
the
same
effect.
specified
length,
though
exact
behavior
can
vary
by
implementation.
or
Unicode
characters.