BIT_AND function [Aggregate]

Takes n bit arrays and returns a bitwise AND-ing of its arguments using the following logic: for each bit compared, if all bits are 1, return 1; otherwise, return 0.

Syntax
BIT_AND( bit-expression )
Parameters
  • expression   The expression for which the value is to be determined. This is commonly a column name.

See also
Standards and compatibility
  • SQL/2003   Vendor extension.

Example

Suppose you have the following table, t, containing a single column, a, which is a VARBIT data type.

a
0001
0111
0100
0011

You want to know the AND value for the column. You enter the following SELECT statement, which returns 0000:

SELECT BIT_AND( a ) FROM t;

This result is determined as follows:

  1. A bitwise AND is performed between row 1 (0001) and row 2 (0111), resulting in 0001 (both values had a 1 in the fourth bit).
  2. A bitwise AND is performed between the result from the previous comparison (0001) and row 3 (0100), resulting in 0000 (neither value had a 1 in the same bit).
  3. A bitwise AND is performed between the result from the previous comparison (0000) and row 4 (0011), resulting in 0000 (neither value had a 1 in the same bit).