SET_BITS function [Aggregate]

Creates a bit array where specific bits, corresponding to values from a set of rows, are set to 1 (TRUE).

Syntax
SET_BITS( expression ) 
Parameters
  • expression   The expression used to determine which bits to set to 1. This is typically a column name.

Returns

LONG VARBIT

Remarks

Rows where the specified values are NULL are ignored.

If there are no rows, NULL is returned.

The length of the result is the largest position that was set to 1.

The SET_BITS function is equivalent to, but faster than, the following statement:

SELECT BIT_OR( SET_BIT( expression ) ) 
FROM table;
See also
Standards and compatibility
  • SQL/2003   Vendor extension.

Example

The following statements return a bit array with the 2nd, 5th, and 10th bits set to 1 (or 0100100001):

CREATE TABLE t( r INTEGER ); 
INSERT INTO t values( 2 ); 
INSERT INTO t values( 5 ); 
INSERT INTO t values(10 ); 
SELECT SET_BITS( r ) FROM t;