> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# bit_shift_right

> 将数值的二进制表示向右移动指定的位数。

将一个数值或者数值表达式的二进制表示向右移动指定的位数。该函数执行**算术右移**。

算术右移时，依次右移一位，尾部丢失，左侧最高位会补充对应的符号位，bit 长度不变。举例，`10101` 算术右移一位的结果是 `11010`。

## 语法

```Haskell theme={null}
bit_shift_right(value, shift)
```

## 参数说明

`value`: 要进行位移的数值或数值表达式。支持如下数据类型：TINYINT、SMALLINT、INT、BIGINT、LARGEINT。

`shift`: 要移动的位数，BIGINT 类型。

## 返回值说明

返回值的数据类型和 `value` 一致。

## 使用说明

* 如果任何一个输入参数为 NULL，则返回 NULL。
* 如果 `shift` 小于 0，则返回 0。
* 对于任意 `value` 值，如果 `shift` 等于 0，则返回原本的 `value` 值。
* 如果 `value` 等于 0，则固定返回 0。
* 如果 `value` 为非整型的数值，会转换为整数进行运算。参见[示例](#示例)。
* 如果 `value` 为 STRING 类型，会转换为整数进行运算。如果 STRING 无法转换为整数，则作为 NULL 处理。参见[示例](#示例)。

## 示例

执行算术右移。

```Plain theme={null}
SELECT bit_shift_right(2, 1);
+-----------------------+
| bit_shift_right(2, 1) |
+-----------------------+
|                     1 |
+-----------------------+

SELECT bit_shift_right(2.2, 1);
+-------------------------+
| bit_shift_right(2.2, 1) |
+-------------------------+
|                       1 |
+-------------------------+

SELECT bit_shift_right("2", 1);
+-------------------------+
| bit_shift_right('2', 1) |
+-------------------------+
|                       1 |
+-------------------------+

SELECT bit_shift_right(-2, 1);
+------------------------+
| bit_shift_right(-2, 1) |
+------------------------+
|                     -1 |
+------------------------+
```

## 相关参考

[bit\_shift\_left](/documents/cn/4.2/sql-reference/sql-functions/bit-functions/bit_shift_left.md)

[bit\_shift\_right\_logical](/documents/cn/4.2/sql-reference/sql-functions/bit-functions/bit_shift_right_logical.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.