Skip to content

Commit

Permalink
Add LPAD() example
Browse files Browse the repository at this point in the history
  • Loading branch information
hfxsd authored and dveeden committed Apr 2, 2024
1 parent 4eefbc0 commit 3fc7142
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions functions-and-operators/string-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,51 @@ SELECT LOWER(-012);

Return the string argument, left-padded with the specified string.

```sql
SELECT LPAD('TiDB',8,'>');
```

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

In the example above the string "TiDB" is left padded until 8 characters with 4 `>` characters.

```sql
SELECT LPAD('TiDB',2,'>');
```

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

In the example above the string "TiDB" is left padded until 2 characters with `>` characters. The result is "Ti". This shows that the string in the first argument will be truncated if it is longer than the second argument.

```sql
SELECT LPAD('TiDB',-2,'>');
```

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

In the example above the string "TiDB" is left padded until -2 characters with `>` characters. The result is NULL as the second argument is negative.

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

Remove leading spaces.
Expand Down
1 change: 1 addition & 0 deletions tidb-roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ You might have been waiting on some items from the last version. The following l

## Recently shipped

- [TiDB 8.0.0 Release Notes](https://docs.pingcap.com/tidb/v8.0/release-8.0.0)
- [TiDB 7.6.0 Release Notes](https://docs.pingcap.com/tidb/v7.6/release-7.6.0)
- [TiDB 7.5.0 Release Notes](https://docs.pingcap.com/tidb/v7.5/release-7.5.0)
- [TiDB 7.4.0 Release Notes](https://docs.pingcap.com/tidb/v7.4/release-7.4.0)
Expand Down

0 comments on commit 3fc7142

Please sign in to comment.