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 MID() and NOT LIKE examples #16955

Merged
merged 6 commits into from
Apr 23, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion functions-and-operators/string-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1172,12 +1172,67 @@ Return a set of comma-separated strings that have the corresponding bit in bits

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

Return a substring starting from the specified position.
The `MID(str, start, end)` function returns a substring starting from the specified `start` position and ends at the optinal `end` position.
dveeden marked this conversation as resolved.
Show resolved Hide resolved
dveeden marked this conversation as resolved.
Show resolved Hide resolved

If any of the arguments are NULL the function returns NULL.

TiDB doesn't support the two arguments variant of this function. See also [Github Issue #52420](https://github.com/pingcap/tidb/issues/52420).

Examples:

In the example below `MID()` returns the input string from the second until (including) the third character.

```sql
SELECT MID('abcdef',2,3);
```

```
+-------------------+
| MID('abcdef',2,3) |
+-------------------+
| bcd |
+-------------------+
1 row in set (0.00 sec)
```

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

Negation of simple pattern matching.

This function does the opposite of [`LIKE`](#like).
dveeden marked this conversation as resolved.
Show resolved Hide resolved

Examples:

In the example below `NOT LIKE` returns 0 (False) as "aaa" is matching the `a%` pattern.
dveeden marked this conversation as resolved.
Show resolved Hide resolved

```sql
SELECT 'aaa' LIKE 'a%', 'aaa' NOT LIKE 'a%';
```

```
+-----------------+---------------------+
| 'aaa' LIKE 'a%' | 'aaa' NOT LIKE 'a%' |
+-----------------+---------------------+
| 1 | 0 |
+-----------------+---------------------+
1 row in set (0.00 sec)
```

In the example below `NOT LIKE` returns 1 (True) as "aaa" is not matching the `b%` pattern.
dveeden marked this conversation as resolved.
Show resolved Hide resolved

```sql
SELECT 'aaa' LIKE 'b%', 'aaa' NOT LIKE 'b%';
```

```
+-----------------+---------------------+
| 'aaa' LIKE 'b%' | 'aaa' NOT LIKE 'b%' |
+-----------------+---------------------+
| 0 | 1 |
+-----------------+---------------------+
1 row in set (0.00 sec)
```

### [`NOT REGEXP`](https://dev.mysql.com/doc/refman/8.0/en/regexp.html#operator_not-regexp)

Negation of `REGEXP`.
Expand Down
Loading