Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LPAD() example #16946

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
dveeden marked this conversation as resolved.
Show resolved Hide resolved

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

Remove leading spaces.
Expand Down