---
title: lpad function
description: Learn the syntax of the lpad function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/lpad
---

# `lpad` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Returns `expr`, left-padded with `pad` to a length of `len`.

## Syntax

```
lpad(expr, len [, pad] )
```

## Arguments

* `expr`: A STRING or BINARY expression to be padded.
* `len`: An INTEGER expression specifying the length of the result string
* `pad`: An optional STRING or BINARY expression specifying the padding.

## Returns

A STRING.

If `expr` is longer than `len`, the return value is shortened to `len` characters.
If you do not specify `pad`, a STRING `expr` is padded to the left with space characters, whereas a BINARY `expr` is padded to the left with x'00' bytes.
If `len` is less than 1, an empty string.

BINARY is supported **since:** [Databricks Runtime 11.0](https://docs.databricks.com/aws/en/release-notes/runtime/11.0.md).

## Examples

```sql
> SELECT lpad('hi', 5, 'ab');
 abahi
> SELECT lpad('hi', 1, '??');
 h
> SELECT lpad('hi', 5);
    hi

> SELECT hex(lpad(x'1020', 5, x'05'))
 0505051020
```

## Related functions

* [`rpad` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/rpad.md)
* [`ltrim` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/ltrim.md)
* [`rtrim` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/rtrim.md)
* [`trim` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/trim.md)
