EXPORT_SET() function in MySQL
Last Updated :
30 Dec, 2020
EXPORT_SET() :
This function helps to return a string which will show the bits in number. The function requires 5 arguments for its functioning. The function converts first argument i.e integer to binary digits, then returns “on” if binary digit is 1 and “off” if binary digit is 0.
Syntax :
EXPORT_SET
(bits, on, off, separator, number of bits)
Parameters :
This function accepts 5 arguments.
- bits -
The integer number for which the result will be formatted.
- on -
If the binary digit is 1, then it will return.
- off -
If the binary digit is 0, then it will return.
- separator -
The separator which will be placed between returned values.
- number of bits -
The number of bits in which the result will come
Returns :
This function will return a string that will show the bits in number.
Example-1 :
General working of EXPORT_SET() function.
SELECT EXPORT_SET(10, 'On', 'Off', ':', 5)
AS Export;
Output :
| Export |
|---|
| Off : On : Off : On : Off |
Example 2 :
Working of EXPORT_SET() function by changing 2
nd and 3
rd arguments.
- Using “Y” and “N” as second and third argument respectively -
SELECT EXPORT_SET(11, 'Y', 'N', ', ', 4)
AS Export;
Output :
- Using “1” and “0” as second and third argument respectively -
SELECT EXPORT_SET(11, 1, 0, ', ', 4)
AS Export;
Output :
Example-3 :
Working of EXPORT_SET() function by changing 4
th argument.
- Using “-” as the fourth argument -
SELECT EXPORT_SET(10, 1, 0, '-', 4)
AS Export;
Output :
- Using “::” as the fourth argument -
SELECT EXPORT_SET(10, 1, 0, '::', 4)
AS Export;
Output :
Example-4 :
Working of EXPORT_SET() function by changing 5
th argument.
- Using 10 as the fifth argument -
SELECT EXPORT_SET(9, 'Y', 'N', ' ', 10)
AS Export;
Output :
| Export |
|---|
| Y N N Y N N N N N N |
- Using 20 as the fifth argument -
SELECT EXPORT_SET(9, 1, 0, ' ', 20)
AS Export;
Output :
| Export |
|---|
| 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
Explore
Basics
Queries & Operations
SQL Joins & Functions
Data Constraints & Aggregate Functions
Advanced SQL Topics
Database Design & Security