^

Description

Bitwise XOR.

The result type depends on whether the arguments are evaluated as binary strings or numbers:

  • Binary-string evaluation occurs when the arguments have a binary string type, and at least one of them is not a hexadecimal literal, bit literal, or NULL literal. Numeric evaluation occurs otherwise, with argument conversion to unsigned 64-bit integers as necessary.

  • Binary-string evaluation produces a binary string of the same length as the arguments. If the arguments have unequal lengths, an ER_INVALID_BITWISE_OPERANDS_SIZE error occurs. Numeric evaluation produces an unsigned 64-bit integer.

Syntax

  1. > SELECT value1 ^ value2;

Examples

  1. mysql> SELECT 1 ^ 1;
  2. +-------+
  3. | 1 ^ 1 |
  4. +-------+
  5. | 0 |
  6. +-------+
  7. 1 row in set (0.00 sec)
  8. mysql> SELECT 1 ^ 0;
  9. +-------+
  10. | 1 ^ 0 |
  11. +-------+
  12. | 1 |
  13. +-------+
  14. 1 row in set (0.01 sec)
  15. mysql> SELECT 11 ^ 3;
  16. +--------+
  17. | 11 ^ 3 |
  18. +--------+
  19. | 8 |
  20. +--------+
  21. 1 row in set (0.01 sec)
  22. mysql> select null ^ 2;
  23. +----------+
  24. | null ^ 2 |
  25. +----------+
  26. | NULL |
  27. +----------+
  28. 1 row in set (0.01 sec)
  29. create table t1(a int, b int unsigned);
  30. insert into t1 values (-1, 1), (-5, 5);
  31. mysql> select a ^ 2, b ^ 2 from t1;
  32. +-------+-------+
  33. | a ^ 2 | b ^ 2 |
  34. +-------+-------+
  35. | -3 | 3 |
  36. | -7 | 7 |
  37. +-------+-------+
  38. 2 rows in set (0.01 sec)