MariaDB EXPORT_SET() Function
In MariaDB, EXPORT_SET() is a built-in string function that generates a string using the specified delimiter based on the bits of the argument.
MariaDB EXPORT_SET() Syntax
Here is the syntax of the MariaDB EXPORT_SET() function:
EXPORT_SET(bits, on, off, separator, length)
Parameters
bits-
Required. A number. Converting
bitsto binary and inverting (from right to left) the value of each bit determines whetheronoroffappears in that position. on-
Required. String to use when the bit value is
1. off-
Required. String to use when the bit value is
0. separator-
Optional. Separator string, default is
,. length-
Optional. The number of elements in the collection, the default value is
64.
You should provide at least 3 parameters, otherwise MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'EXPORT_SET'.
Return value
The MariaDB EXPORT_SET() function selects the corresponding string according to the reversed value of binary of bits, and returns a comma-separated string set.
The EXPORT_SET() function will return NULL if any argument is NULL.
For example EXPORT_SET(5, 'Aa', 'Bb', '#', 4):
-
bits = 5, the binary of5is101(this result can be returned by theBIN()function), the total length is4, and the left complement0becomes0101. Then reverse the value (right to left) to1010. -
Use the value of
onoroffaccording each bit in1010:- The first bit is
1, useAa. - The second bit is
0, useBb. - The third bit is
1, useAa. - The fourth bit is
0, useBb.
- The first bit is
-
Finally, combine them with
#and become toAa#Bb#Aa#Bb.
MariaDB EXPORT_SET() Examples
Basic example
This statement shows the basic usage of the MariaDB EXPORT_SET():
SELECT EXPORT_SET(5, 'Aa', 'Bb', '#', 4);
Output:
+-----------------------------------+
| EXPORT_SET(5, 'Aa', 'Bb', '#', 4) |
+-----------------------------------+
| Aa#Bb#Aa#Bb |
+-----------------------------------+Defaults
If you do not provide a delimiter, MariaDB EXPORT_SET() will use a comma , as the default delimiter.
If you don’t specify a number, MariaDB EXPORT_SET() will use 64 as the default number of bits.
SELECT EXPORT_SET(5, 'A', 'B');
Output:
+---------------------------------------------------------------------------------------------------------------------------------+
| EXPORT_SET(5, 'A', 'B') |
+---------------------------------------------------------------------------------------------------------------------------------+
| A,B,A,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B,B |
+---------------------------------------------------------------------------------------------------------------------------------+Conclusion
In MariaDB, EXPORT_SET() is a built-in string function that returns a string concatenated by the specified delimiter from the string indicated by the binary bits (from high to low) of the first argument.