MariaDB Tutorial MariaDB Advanced MariaDB Database Account Management MariaDB References

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.

MAKE_SET() Function

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:

EmpIDNameDepartment1Department2Department3
1JohnHRAdminTreasury
2MarryITFinance
3JoFinanceMarketing
4KimMarketingSales
5RameshITFinanceMarketing
6HuangITMarketingSales

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:

EmpIDNameDepartment1Department2Department3MAKE_SET_Value
1JohnHRAdminTreasuryHR,Admin,Treasury
2MarryITFinanceIT,Finance
3JoFinanceMarketingFinance,Marketing
4KimMarketingSalesMarketing,Sales
5RameshITFinanceMarketingIT,Finance,Marketing
6HuangITMarketingSalesIT,Marketing,Sales

❮ MariaDB Functions