^
Operator Description
bitwise xOR. Perform an XOR (XOR) operation on each pair of bits. When a and b are not the same, the result of a XOR b is 1.
The result type depends on whether the parameter is a binary string or a number:
-
When the parameters are of binary string type, and at least one of them is not hexadecimal
literal, bitliteralorNULL literal, binary string evaluation is performed; otherwise, numerical evaluation is performed and the parameters are converted to unsigned 64-bit integers as needed. -
Binary string evaluation produces a binary string with the same length as the parameter. If the lengths of the parameters are not equal, an
ER_INVALID_BITWISE_OPERANDS_SIZEerror occurs. Numerical calculations produce an unsigned 64-bit integer.
Grammar Structure
> SELECT value1 ^ value2;
Example
mysql> SELECT 1 ^ 1;
+--------+
| 1 ^ 1 |
+--------+
| 0 |
+--------+
1 row in set (0.00 sec)
mysql> SELECT 1 ^ 0;
+--------+
| 1 ^ 0 |
+--------+
| 1 |
+--------+
1 row in set (0.01 sec)
mysql> SELECT 11 ^ 3;
+---------+
| 11 ^ 3 |
+---------+
| 8 |
+---------+
1 row in set (0.01 sec)
mysql> select null ^ 2;
+-------------+
| null ^ 2 |
+-------------+
| NULL |
+-------------+
1 row in set (0.01 sec)
create table t1(a int, b int unsigned);
insert into t1 values (-1, 1), (-5, 5);
mysql> select a ^ 2, b ^ 2 from t1;
+--------+--------+
| a ^ 2 | b ^ 2 |
+--------+--------+
| -3 | 3 |
| -7 | 7 |
+--------+--------+
2 rows in set (0.01 sec)