Collections:
EXPORT_SET() - Exporting Binary Set to On/Off Flags
How to export an integer as a binary set to on/off flags using the EXPORT_SET() function?
✍: FYIcenter.com
EXPORT_SET(bits, on, off, delimiter, len) is a MySQL built-in function that
converts an integer as a binary set (a sequence of bits) to on/off flags.
It loops through every bit of the given integer "bits" starting
from the lowest bit and converts 1 to "on" or 0 to "off"
separated by "delimiter". It stops after "len" bits.
For example:
SELECT EXPORT_SET(5,'Y','N',',',4), EXPORT_SET(5,'1','0','',4); -- +-----------------------------+----------------------------+ -- | EXPORT_SET(5,'Y','N',',',4) | EXPORT_SET(5,'1','0','',4) | -- +-----------------------------+----------------------------+ -- | Y,N,Y,N | 1010 | -- +-----------------------------+----------------------------+ SELECT EXPORT_SET(6,'1','0',',',10), EXPORT_SET(6,'+','-','',10); -- +------------------------------+-----------------------------+ -- | EXPORT_SET(6,'1','0',',',10) | EXPORT_SET(6,'+','-','',10) | -- +------------------------------+-----------------------------+ -- | 0,1,1,0,0,0,0,0,0,0 | -++------- | -- +------------------------------+-----------------------------+
Reference information of the EXPORT_SET() function:
EXPORT_SET(bits, on, off, delimiter, len): str Converts an integer as a binary set (a sequence of bits) to on/off flags. Arguments, return value and availability: bits: Required. The sequence of bits given as an integer. on: Required. The "on" flag to be used for bit 1. off: Required. The "off" flag to be used for bit 0. delimiter: Optional. The default is ",". Flag string delimiter. len: Optional. The default is 64. Number of bits to be converted. str: Return value. The converted on/off flag string. Available since MySQL 4.
⇒ INTERVAL() - Interval Position of Sorted List
⇐ EXP() - Exponential Based on E
2023-12-20, 1196🔥, 0💬
Popular Posts:
What are DDL (Data Definition Language) statements for tables in SQL Server? DDL (Data Definition La...
What Are Out-of-Range Errors with DATETIME values in SQL Server Transact-SQL? When you enter DATETIM...
How To Convert Binary Strings into Integers in SQL Server Transact-SQL? Binary strings and integers ...
How To Use GO Command in "sqlcmd" in SQL Server? "sqlcmd" is a command line client application to ru...
How To Get a List of All Tables with "sys.tables" View in SQL Server? If you want to see the table y...