All Products
Search
Document Center

Bit functions

Last Updated: Jul 31, 2020

Distributed Relational Database Service (DRDS) supports a bit function, BIT_COUNT(), which returns the number of 1 in the binary numeric of the parameter. If the parameter is NULL, NULL is returned.

  1. mysql> SELECT BIT_COUNT(29), BIT_COUNT(b'101010');
  2. +--------------+----------------------+
  3. | BIT_COUNT(29) | BIT_COUNT(b'101010') |
  4. +--------------+----------------------+
  5. | 4 | 3 |
  6. +--------------+----------------------+
  7. 1 row in set (0.00 sec)
  8. mysql> SELECT BIT_COUNT(NULL);
  9. +-----------------+
  10. | BIT_COUNT(NULL) |
  11. +-----------------+
  12. | NULL |
  13. +-----------------+
  14. 1 row in set (0.00 sec)