MySQL EXPORT_SET function is one of the String Function, which is used to return a string using the separator, on and Off arguments, bit value and number of bits.
In this article, we will show you, How to write MySQL String EXPORT_SET Function query to return a string using bit values and number of bits with an example.
MySQL EXPORT_SET Syntax
The basic syntax of EXPORT_SET of a string in MySQL is as shown below:
EXPORT_SET(bits, On_Str, Off_Str, Separator, Number of Bits)
- Bits: It converts the given value to binary value or bits.
- On_Str and Off_Str: If the first argument bit value is 1 then this is returned. Otherwise, Off_String value is returned.
- Number of Bits: Total number of bits to compare.
MySQL EXPORT_SET Example
The MySQL string EXPORT_SET function returns a string using the bit values, On and Off string with separators. The following query shows multiple ways to use this EXPORT_SET function.
Here, we will take first statement for the analysis purpose. bits = 5 = 0101. As we said earlier, it starts from right to left So, first bit is 1 and it returns On_String A. Next one is 0, so it returns Off_String B. Do the same for the remaining two.
In the second statement, we used the number of bits value to three. It means, 101 so, the output will be A,B,A
SELECT EXPORT_SET(5, 'A', 'B', ',', 4);
SELECT EXPORT_SET(5, 'A', 'B', ',', 3);
SELECT EXPORT_SET(4, '1', '0', ',', 8);
In this MySQL Export_Set example, we are using the large numbers as a bit argument value. Here, we also used the $ as the separator.
SELECT EXPORT_SET(39, '1', '0', ',', 5);
SELECT EXPORT_SET(245, '1', '0', '$', 16);
SELECT EXPORT_SET(24500, '1', '0', ',', 32);
Thank You for Visiting Our Blog