MariaDB MAKE_SET() Function
The MariaDB MAKE_SET() function returns a set value (a string containing substrings separated by "," characters) consisting of the strings that have the corresponding bit in bits set. NULL values in str1, str2, ... are not appended to the result.
Syntax
MAKE_SET(bits, str1, str2, str3,...)
Parameters
bits |
Required. Specify the bits set. |
str1, str2, str3,... |
Required. Specify the list of strings. |
Return Value
Returns a set value (a string containing substrings separated by "," characters) consisting of the strings that have the corresponding bit in bits set.
Example 1:
The example below shows the usage of MAKE_SET() function.
SELECT MAKE_SET(1, 'Learning', 'MariaDB', 'is', 'fun'); Result: 'Learning' SELECT MAKE_SET(1|2, 'Learning', 'MariaDB', 'is', 'fun'); Result: 'Learning,MariaDB' SELECT MAKE_SET(1|4, 'Learning', 'MariaDB', 'is', 'fun'); Result: 'Learning,is' SELECT MAKE_SET(1|6, 'Learning', 'MariaDB', 'is', 'fun'); Result: 'Learning,MariaDB,is' SELECT MAKE_SET(1|8, 'Learning', 'MariaDB', 'is', 'fun'); Result: 'Learning,fun' SELECT MAKE_SET(1|14, 'Learning', 'MariaDB', 'is', 'fun'); Result: 'Learning,MariaDB,is,fun' SELECT MAKE_SET(15, 'Learning', 'MariaDB', 'is', 'fun'); Result: 'Learning,MariaDB,is,fun' SELECT MAKE_SET(15, 'A', 'B', NULL, 'D'); Result: 'A,B,D'
Example 2:
Consider a database table called Employee with the following records:
EmpID | Name | Department1 | Department2 | Department3 |
---|---|---|---|---|
1 | John | HR | Admin | Treasury |
2 | Marry | IT | Finance | |
3 | Jo | Finance | Marketing | |
4 | Kim | Marketing | Sales | |
5 | Ramesh | IT | Finance | Marketing |
6 | Huang | IT | Marketing | Sales |
The statement given below can be used to get the set value specified by bit in bits set.
/* Binary of 28 is 11100 */ SELECT *, MAKE_SET(28, EmpID, Name, Department1, Department2, Department3) AS MAKE_SET_Value FROM Employee;
This will produce the result as shown below:
EmpID | Name | Department1 | Department2 | Department3 | MAKE_SET_Value |
---|---|---|---|---|---|
1 | John | HR | Admin | Treasury | HR,Admin,Treasury |
2 | Marry | IT | Finance | IT,Finance | |
3 | Jo | Finance | Marketing | Finance,Marketing | |
4 | Kim | Marketing | Sales | Marketing,Sales | |
5 | Ramesh | IT | Finance | Marketing | IT,Finance,Marketing |
6 | Huang | IT | Marketing | Sales | IT,Marketing,Sales |
❮ MariaDB Functions