Skip to content

Commit

Permalink
string-functions: add instrunctions for LEFT(), LENGTH() (pingcap#15491)
Browse files Browse the repository at this point in the history
  • Loading branch information
takaidohigasi committed Jan 10, 2024
1 parent 611cdde commit 69b2f2c
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions functions-and-operators/string-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,101 @@ Synonym for `LOWER()`.

Return the leftmost number of characters as specified.

* LEFT(`str`, `len`)
* if `len` is equal or less than 0, the function returns empty string
* function is multibyte safe.
* If any argument is `NULL`, the function returns `NULL`.

Examples:

```sql
SELECT LEFT('ABCED', 3);
+------------------+
| LEFT('ABCED', 3) |
+------------------+
| ABC |
+------------------+

SELECT LEFT('ABCED', 6);
+------------------+
| LEFT('ABCED', 6) |
+------------------+
| ABCED |
+------------------+
```

```sql
SELECT LEFT('ABCED', 0);
+------------------+
| LEFT('ABCED', 0) |
+------------------+
| |
+------------------+

SELECT LEFT('ABCED', -1);
+-------------------+
| LEFT('ABCED', -1) |
+-------------------+
| |
+-------------------+
```

```sql
SELECT LEFT('🍣ABC', 3);
+--------------------+
| LEFT('🍣ABC', 3) |
+--------------------+
| 🍣AB |
+--------------------+
```

```sql
SELECT LEFT('ABC', NULL);
+-------------------+
| LEFT('ABC', NULL) |
+-------------------+
| NULL |
+-------------------+

SELECT LEFT(NULL, 3);
+------------------------------+
| LEFT(NULL, 3) |
+------------------------------+
| NULL |
+------------------------------+
```

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

Return the length of a string in bytes.

Examples:

```sql
SELECT LENGTH('ABC');
+---------------+
| LENGTH('ABC') |
+---------------+
| 3 |
+---------------+

SELECT LENGTH('🍣ABC');
+-------------------+
| LENGTH('🍣ABC') |
+-------------------+
| 7 |
+-------------------+
```

```sql
SELECT LENGTH(NULL);
+--------------+
| LENGTH(NULL) |
+--------------+
| NULL |
+--------------+
```

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

Simple pattern matching.
Expand Down

0 comments on commit 69b2f2c

Please sign in to comment.