>>
Operator Description
This operator moves the first operand to the right by the specified number of bits. The bits moved to the right are discarded, and the left side is supplemented with 0.
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. Numerical calculations produce an unsigned 64-bit integer.
Regardless of the parameter type, the bits that are moved out of the end of the value will be lost without warning. In particular, if the shift count is greater than or equal to the number of bits in the bit parameter, all bits in the result are 0.
Grammar Structure
> SELECT value1 >> value2;
Example
mysql> select 1024 >> 2;
+---------------+
| 1024 >> 2 |
+---------------+
| 256 |
+---------------+
1 row in set (0.01 sec)
mysql> select -5 >> 2;
+-----------+
| -5 >> 2 |
+-----------+
| -2 |
+-----------+
1 row in set (0.01 sec)
mysql> select null >> 2;
+---------------+
| null >> 2 |
+---------------+
| NULL |
+---------------+
1 row in set (0.00 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 |
+--------------------+
| -1 | 0 |
| -2 | 1 |
+--------------------+
2 rows in set (0.01 sec)