~

Description

Invert all bits.

The result type depends on whether the bit argument is evaluated as a binary string or number:

  • Binary-string evaluation occurs when the bit argument has a binary string type, and is not a hexadecimal literal, bit literal, or NULL literal. Numeric evaluation occurs otherwise, with argument conversion to an unsigned 64-bit integer as necessary.

  • Binary-string evaluation produces a binary string of the same length as the bit argument. Numeric evaluation produces an unsigned 64-bit integer.

Syntax

  1. > SELECT value1 ~ value2;

Examples

  1. mysql> select ~-5;
  2. +--------+
  3. | ~ (-5) |
  4. +--------+
  5. | 4 |
  6. +--------+
  7. 1 row in set (0.00 sec)
  8. mysql> select ~null;
  9. +-------+
  10. | ~null |
  11. +-------+
  12. | NULL |
  13. +-------+
  14. 1 row in set (0.00 sec)
  15. mysql> select ~a, ~b from t1;
  16. +------+----------------------+
  17. | ~a | ~b |
  18. +------+----------------------+
  19. | 0 | 18446744073709551614 |
  20. | 4 | 18446744073709551610 |
  21. +------+----------------------+
  22. 2 rows in set (0.00 sec)