MySQL EXPORT_SET function is one of the string Functions, which returns a string using the separator, on and Off arguments, bit value, and the number of bits.

Let me show you how to write MySQL String EXPORT_SET Function query to return a string using bit values and the number of bits with an example.

The basic syntax of MySQL EXPORT_SET function of a string 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, the Off_String value will return.
  • Number of Bits: Total number of bits to compare.

MySQL EXPORT_SET Function Example

The 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 take the first statement for analysis purposes. bits = 5 = 0101. As we said earlier, it starts from right to left. So, the first bit is 1, and it returns On_String A. The next one is 0, so it returns Off_String B. Do the same for the remaining two.

In the second MySQL statement, we used the number of bits value to three. It means, 101 so, the output of this String Function 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 function example, we are using 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);
EXPORT_SET Example 2