Skip to content

Commit 025af3b

Browse files
committed
Add ELT and EXPORT_SET examples
1 parent 47abac9 commit 025af3b

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

functions-and-operators/string-functions.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,63 @@ Output:
406406

407407
### [`ELT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_elt)
408408

409-
Return string at index number.
409+
Returns the element at the index number.
410+
411+
```sql
412+
SELECT ELT(3, 'This', 'is', 'TiDB');
413+
```
414+
415+
```
416+
+------------------------------+
417+
| ELT(3, 'This', 'is', 'TiDB') |
418+
+------------------------------+
419+
| TiDB |
420+
+------------------------------+
421+
1 row in set (0.00 sec)
422+
```
423+
424+
This example returns the third element, which is "TiDB".
410425
411426
### [`EXPORT_SET()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_export-set)
412427
413428
Return a string such that for every bit set in the value bits, you get an on string and for every unset bit, you get an off string.
414429
430+
The full signature of this function is:
431+
432+
```
433+
EXPORT_SET(bits, on, off, [separator, number_of_bits])
434+
```
435+
436+
```sql
437+
SELECT EXPORT_SET(b'00001111', 'x', '_', '', 8);
438+
```
439+
440+
```
441+
+------------------------------------------+
442+
| EXPORT_SET(b'00001111', 'x', '_', '', 8) |
443+
+------------------------------------------+
444+
| xxxx____ |
445+
+------------------------------------------+
446+
1 row in set (0.00 sec)
447+
```
448+
449+
In the example above `bits` is set to `00001111` and this causes the function to return `____` for the bits that are set to 0 and `xxxx` for the bits that are set to 1. Here `x` means "on" and "_" means "off".
450+
451+
```sql
452+
SELECT EXPORT_SET(b'01010101', 'x', '_', '', 8);
453+
```
454+
455+
```
456+
+------------------------------------------+
457+
| EXPORT_SET(b'01010101', 'x', '_', '', 8) |
458+
+------------------------------------------+
459+
| x_x_x_x_ |
460+
+------------------------------------------+
461+
1 row in set (0.00 sec)
462+
```
463+
464+
In the example above you can see the off (`_`) / on (`x`) pattern from right to left as set by the `bits.
465+
415466
### [`FIELD()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_field)
416467

417468
Return the index (position)of the first argument in the subsequent arguments.

0 commit comments

Comments
 (0)