Skip to content

Commit

Permalink
Add LPAD() example (#16946)
Browse files Browse the repository at this point in the history
  • Loading branch information
dveeden committed Apr 3, 2024
1 parent ffb3a2c commit d14cb24
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion functions-and-operators/string-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,43 @@ SELECT LOWER(-012);

### [`LPAD()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_lpad)

Return the string argument, left-padded with the specified string.
The `LPAD(str, len, padstr)` function returns the string argument, left-padded with the specified string `padstr` to a length of `len` characters.

- If `len` is less than the length of the string `str`, the function truncates the string `str` to the length of `len`.
- If `len` is a negative number, the function returns `NULL`.
- If any argument is `NULL`, the function returns `NULL`.

Examples:

```sql
SELECT LPAD('TiDB',8,'>');
+--------------------+
| LPAD('TiDB',8,'>') |
+--------------------+
| >>>>TiDB |
+--------------------+
1 row in set (0.00 sec)
```

```sql
SELECT LPAD('TiDB',2,'>');
+--------------------+
| LPAD('TiDB',2,'>') |
+--------------------+
| Ti |
+--------------------+
1 row in set (0.00 sec)
```

```sql
SELECT LPAD('TiDB',-2,'>');
+---------------------+
| LPAD('TiDB',-2,'>') |
+---------------------+
| NULL |
+---------------------+
1 row in set (0.00 sec)
```

### [`LTRIM()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_ltrim)

Expand Down

0 comments on commit d14cb24

Please sign in to comment.