Skip to main content
Version: V1.0.0

BIT_OR

Declaration

BIT_OR(expr) OVER (analytic_clause)

Description

Returns the bitwise OR of all bits in expr.

The result type depends on whether the function arguments are evaluated as binary strings or numbers. If the argument values are of the binary string type and are not hexadecimal literals, bit literals, or NULL literals, binary string evaluation occurs; otherwise, numeric calculation occurs, and the argument values are converted to unsigned 64-bit integers as needed.

If no matching rows are found, BIT_OR() returns a neutral value with the same length as the argument value (all bits set to 0). NULL values do not affect the result unless all values are NULL, in which case the result is a neutral value with the same length as the argument value.

Examples

CREATE TABLE tbl1 (year YEAR (4), month INT(2)UNSIGNED ZEROFILL, day INT(2) UNSIGNED ZEROFILL);
INSERT INTO tbl1 VALUES(2021,1,1),(2021,1,22),(2021,1,3),(2021,2,2), (2021,2,23),(2021,2,23);

SELECT * FROM tbl1;
+------+-------+------+
| year | month | day |
+------+-------+------+
| 2021 | 01 | 01 |
| 2021 | 01 | 22 |
| 2021 | 01 | 03 |
| 2021 | 02 | 02 |
| 2021 | 02 | 23 |
| 2021 | 02 | 23 |
+------+-------+------+
6 rows in set (0.002 sec)

SELECT year,month,BIT_OR(day) OVER (PARTITION BY year, month) AS days FROM tbl1;
+------+-------+------+
| year | month | days |
+------+-------+------+
| 2021 | 01 | 23 |
| 2021 | 01 | 23 |
| 2021 | 01 | 23 |
| 2021 | 02 | 23 |
| 2021 | 02 | 23 |
| 2021 | 02 | 23 |
+------+-------+------+
6 rows in set (0.002 sec)