This is an automated email from the ASF dual-hosted git repository. kassiez pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push: new 034020f6c6d [doc]Bit processing function documentation modification (#1832) 034020f6c6d is described below commit 034020f6c6db41cd037216503cdd332814d399cc Author: qsy840035156 <84378371+qsy840035...@users.noreply.github.com> AuthorDate: Tue Jan 21 15:41:54 2025 +0800 [doc]Bit processing function documentation modification (#1832) bit_count bit_length bit_shift_left bit_shift_right bit_test, bit_test_all xor bitand bitnot bitor --------- Co-authored-by: morrySnow <morrys...@126.com> --- .../bitwise-functions/bit-length.md | 46 ++++++++------- .../scalar-functions/bitwise-functions/bit_test.md | 61 +++++++++---------- .../scalar-functions/bitwise-functions/bitand.md | 50 ++++++++-------- .../scalar-functions/bitwise-functions/bitcount.md | 35 ++++++----- .../scalar-functions/bitwise-functions/bitnot.md | 48 ++++++++------- .../scalar-functions/bitwise-functions/bitor.md | 49 ++++++++-------- .../bitwise-functions/bitshiftleft.md | 61 ++++++++----------- .../bitwise-functions/bitshiftright.md | 68 ++++++++-------------- .../scalar-functions/bitwise-functions/xor.md | 48 ++++++++------- .../scalar-functions/bitwise-functions/bit-and.md | 45 +++++++------- .../bitwise-functions/bit-count.md | 29 ++++----- .../bitwise-functions/bit-length.md | 40 +++++++------ .../scalar-functions/bitwise-functions/bit-not.md | 47 ++++++++------- .../scalar-functions/bitwise-functions/bit-or.md | 46 ++++++++------- .../bitwise-functions/bit-shift-left.md | 56 +++++++----------- .../bitwise-functions/bit-shift-right.md | 68 +++++++++------------- .../scalar-functions/bitwise-functions/bit-test.md | 60 ++++++++++--------- .../scalar-functions/bitwise-functions/xor.md | 30 ++++++---- .../scalar-functions/bitwise-functions/bit-and.md | 44 +++++++------- .../bitwise-functions/bit-count.md | 34 ++++++----- .../bitwise-functions/bit-length.md | 40 +++++++------ .../scalar-functions/bitwise-functions/bit-not.md | 46 +++++++-------- .../scalar-functions/bitwise-functions/bit-or.md | 45 +++++++------- .../bitwise-functions/bit-shift-left.md | 55 +++++++---------- .../bitwise-functions/bit-shift-right.md | 67 ++++++++------------- .../scalar-functions/bitwise-functions/bit-and.md | 44 +++++++------- .../bitwise-functions/bit-count.md | 33 ++++++----- .../bitwise-functions/bit-length.md | 39 +++++++------ .../scalar-functions/bitwise-functions/bit-not.md | 46 +++++++-------- .../scalar-functions/bitwise-functions/bit-or.md | 45 +++++++------- .../bitwise-functions/bit-shift-left.md | 56 +++++++----------- .../bitwise-functions/bit-shift-right.md | 67 ++++++++------------- .../scalar-functions/bitwise-functions/xor.md | 30 ++++++---- .../bitwise-functions/bit-length.md | 46 ++++++++------- .../scalar-functions/bitwise-functions/bitand.md | 50 ++++++++-------- .../scalar-functions/bitwise-functions/bitcount.md | 35 ++++++----- .../scalar-functions/bitwise-functions/bitnot.md | 48 ++++++++------- .../scalar-functions/bitwise-functions/bitor.md | 49 ++++++++-------- .../bitwise-functions/bitshiftleft.md | 62 ++++++++------------ .../bitwise-functions/bitshiftright.md | 68 ++++++++-------------- .../bitwise-functions/bit-length.md | 46 ++++++++------- .../scalar-functions/bitwise-functions/bitand.md | 50 ++++++++-------- .../scalar-functions/bitwise-functions/bitcount.md | 35 ++++++----- .../scalar-functions/bitwise-functions/bitnot.md | 48 ++++++++------- .../scalar-functions/bitwise-functions/bitor.md | 49 ++++++++-------- .../bitwise-functions/bitshiftleft.md | 61 ++++++++----------- .../bitwise-functions/bitshiftright.md | 68 ++++++++-------------- .../scalar-functions/bitwise-functions/xor.md | 48 ++++++++------- 48 files changed, 1117 insertions(+), 1224 deletions(-) diff --git a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md index d9ccfd4a85c..3595b203afd 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md +++ b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md @@ -24,31 +24,35 @@ specific language governing permissions and limitations under the License. --> -## bit_length -### Description -#### Syntax +## Description -`INT bit_length (VARCHAR str)` +It is used to return the median of the binary representation of a string (that is, the total number of binary digits). It calculates the number of bits occupied by the binary encoding of the string. +## Syntax +```sql +BIT_LENGTH( <str>) +``` + +## Parameters +| parameter | description | +|-----------|-------------| +| `<str>` | The string to be calculated | + +## Return Value -Return length of argument in bits. +Returns the number of bits occupied by `<str>` in the binary representation, including all 0 and 1. -### example +## Examples +```sql +select BIT_LENGTH("abc"), BIT_LENGTH("中国"), BIT_LENGTH(123); ``` -mysql> select bit_length("abc"); -+-------------------+ -| bit_length('abc') | -+-------------------+ -| 24 | -+-------------------+ - -mysql> select bit_length("中国"); -+----------------------+ -| bit_length('中国') | -+----------------------+ -| 48 | -+----------------------+ + +```text ++-------------------+----------------------+-----------------------------------------+ +| bit_length('abc') | bit_length('中国') | bit_length(cast(123 as VARCHAR(65533))) | ++-------------------+----------------------+-----------------------------------------+ +| 24 | 48 | 24 | ++-------------------+----------------------+-----------------------------------------+ ``` -### keywords - BIT_LENGTH + diff --git a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit_test.md b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit_test.md index dcb6a80c8ab..0f83b987841 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit_test.md +++ b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit_test.md @@ -24,42 +24,43 @@ specific language governing permissions and limitations under the License. --> -## bit_test -### description -#### Syntax +## Description +Convert the value of `<x>` to binary form and return the value of the specified position `<bits>`, where `<bits>` starts from 0 and goes from right to left. -`bit_test(Integer-type value, Integer-type pos, '......')` +If `<bits>` has multiple values, the values at multiple `<bits>` positions are combined using the AND operator and the final result is returned. -"Convert the value of 'value' into binary form and return the value at the specified position 'pos', where 'pos' starts from 0 and goes from right to left. If there are multiple values for 'pos', combine the values at multiple 'pos' positions using the AND operator and return the final result. -If the value of pos is negative or exceeds the total number of bits in value, the result will be 0. -Integer value ranges: TINYINT, SMALLINT, INT, BIGINT, LARGEINT." +If the value of `<bits>` is negative or exceeds the total number of bits in `<x>`, the result will be 0. -### example +Integer `<x>` range: TINYINT, SMALLINT, INT, BIGINT, LARGEINT. -### example +## Alias +- BIT_TEST_ALL -mysql [(none)]>SELECT bit_test(43, 1); -+-----------------+ -| bit_test(43, 1) | -+-----------------+ -| 1 | -+-----------------+ +## Syntax +```sql +BIT_TEST( <x>, <bits>[, <bits> ... ]) +``` -mysql [(none)]>select bit_test(43,-1); -+------------------+ -| bit_test(43, -1) | -+------------------+ -| 0 | -+------------------+ +## Parameters +| parameter | description | +|-----------|-------------| +| `<x>` | The integer to be calculated | +| `<bits>` | The value at the specified position | -mysql [(none)]>SELECT bit_test(43, 0, 1, 3, 5,2); -+-----------------------------+ -| bit_test(43, 0, 1, 3, 5, 2) | -+-----------------------------+ -| 0 | -+-----------------------------+ -``` +## Return Value + +Returns the value at the specified position -### keywords +## Examples + +```sql +select BIT_TEST(43, 1), BIT_TEST(43, -1), BIT_TEST(43, 0, 1, 3, 5,2); +``` - bit_test,bit_test_all +```text ++-----------------+------------------+-----------------------------+ +| bit_test(43, 1) | bit_test(43, -1) | bit_test(43, 0, 1, 3, 5, 2) | ++-----------------+------------------+-----------------------------+ +| 1 | 0 | 0 | ++-----------------+------------------+-----------------------------+ +``` \ No newline at end of file diff --git a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitand.md b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitand.md index 2b22e80945e..7646d17a03d 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitand.md +++ b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitand.md @@ -24,34 +24,38 @@ specific language governing permissions and limitations under the License. --> -## bitand -### description -#### Syntax +## Description +Used to perform a bitwise AND operation. The bitwise AND operation compares each bit of two integers. The result is 1 only when both corresponding binary bits are 1, otherwise it is 0. -`BITAND(Integer-type lhs, Integer-type rhs)` +Integer range: TINYINT, SMALLINT, INT, BIGINT, LARGEINT -Returns the result of the AND operation of two integers. +## Syntax +```sql +BITAND( <lhs>, <rhs>) +``` -Integer range: TINYINT、SMALLINT、INT、BIGINT、LARGEINT +## Parameters +| parameter | description | +|-----------|--------------| +| `<lhs>` | The first number involved in the bitwise AND operation | +| `<rhs>` | The second number to be included in the bitwise AND operation | -### example +## Return Value -``` -mysql> select bitand(3,5) ans; -+------+ -| ans | -+------+ -| 1 | -+------+ - -mysql> select bitand(4,7) ans; -+------+ -| ans | -+------+ -| 4 | -+------+ +Returns the result of the AND operation on two integers. + + +## Examples + +```sql +select BITAND(3,5), BITAND(4,7); ``` -### keywords +```text ++---------+---------+ +| (3 & 5) | (4 & 7) | ++---------+---------+ +| 1 | 4 | ++---------+---------+ - BITAND +``` diff --git a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitcount.md b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitcount.md index 2518e35f2f1..8ec5798c5f5 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitcount.md +++ b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitcount.md @@ -24,29 +24,32 @@ specific language governing permissions and limitations under the License. --> -## bit_count -### description -#### Syntax +## Description +Used to return the number of 1 bits in the binary representation of an integer value. This function can be used to quickly count the number of "active" bits of an integer in the binary representation, and is usually used to analyze data distribution or perform certain bit operations -`BIT_COUNT(Integer-type x)` +## Syntax +```sql +BIT_COUNT( <x>) +``` -Returns the exist count of one in 2's complement represent of integer x. +## Parameters +| parameter | description | +|-----------|-----------------------------------------------------------------| +| `<x>` | Counts the number of 1s in the binary representation of integer x. Integer types can be: TINYINT, SMALLINT, INT, BIGINT, LARGEINT | -Integer-type could be: TINYINT、SMALLINT、INT、BIGINT、LARGEINT +## Return Value -### example +Returns the number of 1s in the binary representation of `<x>` -``` -select "0b11111111", bit_count(-1) --------------- +## Examples +```sql +select BIT_COUNT(8), BIT_COUNT(-1); +``` +```text +--------------+---------------+ -| '0b11111111' | bit_count(-1) | +| bit_count(8) | bit_count(-1) | +--------------+---------------+ -| 0b11111111 | 8 | +| 1 | 8 | +--------------+---------------+ ``` - -### keywords - - BITCOUNT, BIT_COUNT diff --git a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitnot.md b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitnot.md index 83464888edf..d6f480079da 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitnot.md +++ b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitnot.md @@ -24,34 +24,32 @@ specific language governing permissions and limitations under the License. --> -## bitnot -### description -#### Syntax - -`BITNOT(Integer-type value)` - -Returns the result of the NOT operation of one integer. +## Description +Used to perform a bitwise inversion operation on an integer. Integer range: TINYINT、SMALLINT、INT、BIGINT、LARGEINT -### example - -``` -mysql> select bitnot(7) ans; -+------+ -| ans | -+------+ -| -8 | -+------+ - -mysql> select bitxor(-127) ans; -+------+ -| ans | -+------+ -| 126 | -+------+ +## Syntax +```sql +BITNOT( <x>) ``` -### keywords +## Parameters +| parameter | description | +|-----------|-------------| +| `<x>` | Integer operations | + +## Return Value +Returns the result of the NOT operation of one integer. - BITNOT +## Examples +```sql +select BITNOT(7), BITNOT(-127); +``` +```text ++-------+----------+ +| (~ 7) | (~ -127) | ++-------+----------+ +| -8 | 126 | ++-------+----------+ +``` \ No newline at end of file diff --git a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitor.md b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitor.md index 1a9357db7b9..0a2cd82ffe4 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitor.md +++ b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitor.md @@ -24,34 +24,35 @@ specific language governing permissions and limitations under the License. --> -## bitor -### description -#### Syntax +## Description +Used to perform a bitwise OR operation on two integers. -`BITOR(Integer-type lhs, Integer-type rhs)` +Integer range: TINYINT, SMALLINT, INT, BIGINT, LARGEINT -Returns the result of the OR operation of two integers. +## Syntax +```sql +BITOR( <lhs>, <rhs>) +``` -Integer range: TINYINT、SMALLINT、INT、BIGINT、LARGEINT +## Parameters +| parameter | description | +|-----------|-------------------------------------------------------------------------| +| `<lhs>` | The first BOOLEAN value to be evaluated | +| `<rhs>` | The second BOOLEAN value to be evaluated | -### example +## Return Value -``` -mysql> select bitor(3,5) ans; -+------+ -| ans | -+------+ -| 7 | -+------+ - -mysql> select bitor(4,7) ans; -+------+ -| ans | -+------+ -| 7 | -+------+ -``` +Returns the result of the OR operation on two integers. -### keywords +## Examples +```sql +select BITOR(3,5), BITOR(4,7); +``` - BITOR +```text ++---------+---------+ +| (3 | 5) | (4 | 7) | ++---------+---------+ +| 7 | 7 | ++---------+---------+ +``` \ No newline at end of file diff --git a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftleft.md b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftleft.md index b48313c242b..8ebe5b72741 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftleft.md +++ b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftleft.md @@ -24,48 +24,35 @@ specific language governing permissions and limitations under the License. --> -## bit_shift_left -### description -#### syntax +## Description +Functions for left shift operations are usually used to perform bit shift operations, which shift all bits of a binary number to the left by a specified number of bits. It is a form of bitwise operation that is often used to process binary data or perform efficient mathematical calculations. -`BIT_SHIFT_LEFT(BIGINT x, TINYINT c)` +For the maximum value of BIGINT type, 9223372036854775807, a one-bit left shift results in -2. +## Syntax +```sql +BIT_SHIFT_LEFT( <x>, <bits>) +``` -Do logical left shift to `BIGINT` type x by c bits, and return result as a `BIGINT`. -Return zero if `c` is less than 0. +## Parameters +| parameter | description | +|-----------|-----------------------------------| +| `<x>` | The number to be shifted | +| `<bits>` |The number of bits to shift left. It is an integer that determines how many bits `<x>` will be shifted left | -### example -Normal case -```sql -select 8 as x, number as c, bit_shift_left(8, number) as bit_shift_left from numbers("number"="5") --------------- +## Return Value -+------+------+----------------+ -| x | c | bit_shift_left | -+------+------+----------------+ -| 8 | 0 | 8 | -| 8 | 1 | 16 | -| 8 | 2 | 32 | -| 8 | 3 | 64 | -| 8 | 4 | 128 | -+------+------+----------------+ -5 rows in set (0.04 sec) -``` -Left shift result of `9223372036854775807` which is `BIGINT_MAX` by 1 bit will get -2. +Returns an integer representing the result of a left shift operation. + +## Examples ```sql -WITH tbl AS ( - SELECT 9223372036854775807 AS BIGINT_MAX -) -SELECT BIGINT_MAX, bit_shift_left(BIGINT_MAX, 1) -FROM tbl --------------- +select BIT_SHIFT_LEFT(5, 2), BIT_SHIFT_LEFT(-5, 2), BIT_SHIFT_LEFT(9223372036854775807, 1); +``` -+---------------------+-------------------------------+ -| BIGINT_MAX | bit_shift_left(BIGINT_MAX, 1) | -+---------------------+-------------------------------+ -| 9223372036854775807 | -2 | -+---------------------+-------------------------------+ -1 row in set (0.05 sec) +```text ++----------------------+-----------------------+----------------------------------------+ +| bit_shift_left(5, 2) | bit_shift_left(-5, 2) | bit_shift_left(9223372036854775807, 1) | ++----------------------+-----------------------+----------------------------------------+ +| 20 | -20 | -2 | ++----------------------+-----------------------+----------------------------------------+ ``` -### keywords - BITSHIFT, BITSHIFTLEFT diff --git a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftright.md b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftright.md index 8d44c3421be..2330a4bc6f4 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftright.md +++ b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftright.md @@ -24,56 +24,38 @@ specific language governing permissions and limitations under the License. --> -## bit_shift_right -### description -#### syntax +## Description +Used for right shift operations, usually used to shift all bits of a binary number to the right by a specified number of bits. This operation is usually used to process binary data, or for some mathematical calculations (such as efficient implementation of division). -`BIT_SHIFT_RIGHT(BIGINT x, TINYINT c)` +The result of logically shifting -1 right by one position is BIGINT_MAX(9223372036854775807). -Return result of logical right shift of `BIGINT` type x by c bits. +Shifting a number right by a negative amount always results in a result of 0. -### example -Normal case +## Syntax ```sql -select 1024 as x, number as c, bit_shift_right(1024, number) as bit_shift_right from numbers("number"="5") --------------- - -+------+------+-----------------+ -| x | c | bit_shift_right | -+------+------+-----------------+ -| 1024 | 0 | 1024 | -| 1024 | 1 | 512 | -| 1024 | 2 | 256 | -| 1024 | 3 | 128 | -| 1024 | 4 | 64 | -+------+------+-----------------+ -5 rows in set (0.03 sec) +BIT_SHIFT_RIGHT( <x>, <bits>) ``` -Logical right shift `BIGINT` -1 by 1 bits gets `BIGINT_MAX` -```sql -select bit_shift_right(-1, 1) --------------- -+------------------------+ -| bit_shift_right(-1, 1) | -+------------------------+ -| 9223372036854775807 | -+------------------------+ -``` -Return zero if `c` is less than 0 -```sql -select bit_shift_right(100, -1) --------------- +## Parameters +| parameter | description | +|-----------|----------------------------------| +| `<x>` | The number to be shifted | +| `<bits>` | The number of bits to shift right. It is an integer that determines how many bits `<x>` will be shifted right. | -+--------------------------+ -| bit_shift_right(100, -1) | -+--------------------------+ -| 0 | -+--------------------------+ -1 row in set (0.04 sec) -``` +## Return Value +Returns an integer representing the result of a right shift operation. -### keywords +## Examples - BITSHIFT, BITSHIFTRIGHT +```sql +select BIT_SHIFT_RIGHT(1024,3), BIT_SHIFT_RIGHT(-1,1), BIT_SHIFT_RIGHT(100, -1); +``` + +```text ++--------------------------+------------------------+--------------------------+ +| bit_shift_right(1024, 3) | bit_shift_right(-1, 1) | bit_shift_right(100, -1) | ++--------------------------+------------------------+--------------------------+ +| 128 | 9223372036854775807 | 0 | ++--------------------------+------------------------+--------------------------+ +``` diff --git a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md index 94e54bde4e5..3f545b437a2 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md +++ b/docs/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md @@ -24,34 +24,32 @@ specific language governing permissions and limitations under the License. --> -## bitxor -### description -#### Syntax +## Description +Performs a bitwise exclusive OR operation on two BOOLEAN values. -`BITXOR(Integer-type lhs, Integer-type rhs)` - -Returns the result of the XOR operation of two integers. +## Syntax +```sql + <lhs> XOR <rhs> +``` -Integer range: TINYINT, SMALLINT, INT, BIGINT, LARGEINT +## Parameters +| parameter | description | +|-----------|-------------------------------------------------------------------------| +| `<lhs>` | The first BOOLEAN value to be evaluated | +| `<rhs>` | The second BOOLEAN value to be evaluated | -### example +## Return Value +Returns the exclusive OR of two BOOLEAN values. -``` -mysql> select bitxor(3,5) ans; -+------+ -| ans | -+------+ -| 7 | -+------+ - -mysql> select bitxor(1,7) ans; -+------+ -| ans | -+------+ -| 6 | -+------+ +## Examples +```sql +select true XOR false,true XOR true; ``` -### keywords - - BITXOR +```text ++------------------+-----------------+ +| xor(TRUE, FALSE) | xor(TRUE, TRUE) | ++------------------+-----------------+ +| 1 | 0 | ++------------------+-----------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-and.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-and.md index d292aa8cbff..904fe49726f 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-and.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-and.md @@ -24,34 +24,39 @@ specific language governing permissions and limitations under the License. --> -## bitand + ## 描述 +用于执行 按位与(bitwise AND)运算。按位与运算会对两个整数的每一位进行比较,当两个对应的二进制位都为 1 时,结果才为 1,否则为 0。 + +整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT + ## 语法 +```sql +BITAND( <lhs>, <rhs>) +``` -`BITAND(Integer-type lhs, Integer-type rhs)` +## 参数 +| 参数 | 说明 | +|-------|--------------| +| `<lhs>` | 参与按位与运算的第一个数 | +| `<rhs>` | 参与按位与运算的第二个数 | -返回两个整数与运算的结果. +## 返回值 + +返回两个整数与运算的结果。 -整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT ## 举例 -``` -mysql> select bitand(3,5) ans; -+------+ -| ans | -+------+ -| 1 | -+------+ - -mysql> select bitand(4,7) ans; -+------+ -| ans | -+------+ -| 4 | -+------+ +```sql +select BITAND(3,5), BITAND(4,7); ``` -### keywords +```text ++---------+---------+ +| (3 & 5) | (4 & 7) | ++---------+---------+ +| 1 | 4 | ++---------+---------+ - BITAND +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-count.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-count.md index 1690f95b525..a7becab59b0 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-count.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-count.md @@ -1,7 +1,7 @@ --- { "title": "BIT_COUNT", -"language": "zh-CH" +"language": "zh-CN" } --- @@ -27,31 +27,32 @@ under the License. ## 描述 -用于返回一个整数值的二进制表示中 1 的位数。这个函数可以用于快速统计某个整数在二进制表示中 “活跃” 的位数,通常用于分析数据的分布或进行某些位运算。 +用于返回一个整数值的二进制表示中 1 的位数。这个函数可以用于快速统计某个整数在二进制表示中 “活跃” 的位数,通常用于分析数据的分布或进行某些位运算 ## 语法 ```sql -BIT_COUNT( Integer-type <int> ) +BIT_COUNT( <x>) ``` +## 参数 +| 参数 | 说明 | +|-------| -- | +| `<x>` | 统计整型 x 的二进制表示中 1 的个数。整型可以是:TINYINT、SMALLINT、INT、BIGINT、LARGEINT | -统计整型 x 的二的补码表示中 1 的个数。 -整型可以是:TINYINT、SMALLINT、INT、BIGINT、LARGEINT +## 返回值 + +返回 `<x>` 的二进制表示中 1 的个数 ## 举例 +```sql +select BIT_COUNT(8), BIT_COUNT(-1); ``` -select "0b11111111", bit_count(-1) --------------- - +```text +--------------+---------------+ -| '0b11111111' | bit_count(-1) | +| bit_count(8) | bit_count(-1) | +--------------+---------------+ -| 0b11111111 | 8 | +| 1 | 8 | +--------------+---------------+ ``` - -### keywords - - BITCOUNT, BIT_COUNT diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md index bc447fb6845..9d595b471e1 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md @@ -24,31 +24,35 @@ specific language governing permissions and limitations under the License. --> -## bit_length ## 描述 + +用于返回一个字符串的 二进制表示 中 位数(即总的二进制位数)。它计算的是字符串的二进制编码所占的位数。 + ## 语法 +```sql +BIT_LENGTH( <str>) +``` -`INT bit_length(VARCHAR str)` +## 参数 +| 参数 | 说明 | +|-------|------------| +| `<str>` | 需计算的字符串 | +## 返回值 -返回字符串的位长度。 +返回 `<str>` 的二进制表示中所占用的位数,包括所有的 0 和 1。 ## 举例 +```sql +select BIT_LENGTH("abc"), BIT_LENGTH("中国"), BIT_LENGTH(123); ``` -mysql> select bit_length("abc"); -+-------------------+ -| bit_length('abc') | -+-------------------+ -| 24 | -+-------------------+ - -mysql> select bit_length("中国"); -+----------------------+ -| bit_length('中国') | -+----------------------+ -| 48 | -+----------------------+ + +```text ++-------------------+----------------------+-----------------------------------------+ +| bit_length('abc') | bit_length('中国') | bit_length(cast(123 as VARCHAR(65533))) | ++-------------------+----------------------+-----------------------------------------+ +| 24 | 48 | 24 | ++-------------------+----------------------+-----------------------------------------+ ``` -### keywords - BIT_LENGTH + diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-not.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-not.md index 9bb726ddd09..8d39e6ba189 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-not.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-not.md @@ -24,34 +24,33 @@ specific language governing permissions and limitations under the License. --> -## bitnot + ## 描述 -## 语法 +用于对整数进行按位取反操作。 -`BITNOT(Integer-type value)` +整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT。 -返回一个整数取反运算的结果. +## 语法 +```sql +BITNOT( <x>) +``` -整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT +## 参数 +| 参数 | 说明 | +|-------|--------| +| `<x>` | 参与运算整数 | -## 举例 +## 返回值 +返回一个整数取反运算的结果 +## 举例 +```sql +select BITNOT(7), BITNOT(-127); ``` -mysql> select bitnot(7) ans; -+------+ -| ans | -+------+ -| -8 | -+------+ - -mysql> select bitxor(-127) ans; -+------+ -| ans | -+------+ -| 126 | -+------+ -``` - -### keywords - - BITNOT +```text ++-------+----------+ +| (~ 7) | (~ -127) | ++-------+----------+ +| -8 | 126 | ++-------+----------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-or.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-or.md index 9c003e8c607..649a1161bc9 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-or.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-or.md @@ -24,34 +24,36 @@ specific language governing permissions and limitations under the License. --> -## bitor + ## 描述 +用于对两个整数进行按位或操作。 + +整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT + ## 语法 +```sql +BITOR( <lhs>, <rhs>) +``` -`BITOR(Integer-type lhs, Integer-type rhs)` +## 参数 +| 参数 | 说明 | +|-------|--------------| +| `<lhs>` | 参与运算的第一个数 | +| `<rhs>` | 参与运算的第二个数 | -返回两个整数或运算的结果. +## 返回值 -整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT +返回两个整数或运算的结果. ## 举例 - +```sql +select BITOR(3,5), BITOR(4,7); ``` -mysql> select bitor(3,5) ans; -+------+ -| ans | -+------+ -| 7 | -+------+ - -mysql> select bitor(4,7) ans; -+------+ -| ans | -+------+ -| 7 | -+------+ -``` - -### keywords - BITOR +```text ++---------+---------+ +| (3 | 5) | (4 | 7) | ++---------+---------+ +| 7 | 7 | ++---------+---------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-left.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-left.md index eb4bb4966e0..55d7ad4c9b6 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-left.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-left.md @@ -24,48 +24,36 @@ specific language governing permissions and limitations under the License. --> -## bit_shift_left + ## 描述 +用于 左移 操作的函数,通常用于执行 位移操作,将二进制数字的所有位向左移动指定的位数。它是位运算的一种形式,常用于处理二进制数据或进行高效的数学计算。 + +对于 BIGINT 类型的最大值 9223372036854775807,进行一位左移的结果将得到 -2。 ## 语法 +```sql +BIT_SHIFT_LEFT( <x>, <bits>) +``` -`BIT_SHIFT_LEFT(BIGINT x, TINYINT c)` +## 参数 +| 参数 | 说明 | +|-------|---------------------------------| +| `<x>` | 需要进行位移的数字 | +| `<bits>` | 需要左移的位数。它是一个整数,决定了 `<x>` 将被左移多少位 | -将 BIGINT 类型的 x 向左移动 c 位,并将结果作为 BIGINT 返回。 -如果 c 小于 0,则返回零。 +## 返回值 + +返回一个整数,表示左移操作后的结果。 ## 举例 ```sql -select 8 as x, number as c, bit_shift_left(8, number) as bit_shift_left from numbers("number"="5") --------------- - -+------+------+----------------+ -| x | c | bit_shift_left | -+------+------+----------------+ -| 8 | 0 | 8 | -| 8 | 1 | 16 | -| 8 | 2 | 32 | -| 8 | 3 | 64 | -| 8 | 4 | 128 | -+------+------+----------------+ -5 rows in set (0.04 sec) +select BIT_SHIFT_LEFT(5, 2), BIT_SHIFT_LEFT(-5, 2), BIT_SHIFT_LEFT(9223372036854775807, 1); ``` -对于 BIGINT 类型的最大值 9223372036854775807(即 BIGINT_MAX),进行一位左移的结果将得到 -2。 -```sql -WITH tbl AS ( - SELECT 9223372036854775807 AS BIGINT_MAX -) -SELECT BIGINT_MAX, bit_shift_left(BIGINT_MAX, 1) -FROM tbl --------------- -+---------------------+-------------------------------+ -| BIGINT_MAX | bit_shift_left(BIGINT_MAX, 1) | -+---------------------+-------------------------------+ -| 9223372036854775807 | -2 | -+---------------------+-------------------------------+ -1 row in set (0.05 sec) +```text ++----------------------+-----------------------+----------------------------------------+ +| bit_shift_left(5, 2) | bit_shift_left(-5, 2) | bit_shift_left(9223372036854775807, 1) | ++----------------------+-----------------------+----------------------------------------+ +| 20 | -20 | -2 | ++----------------------+-----------------------+----------------------------------------+ ``` -### keywords - - BITSHIFT, BITSHIFTLEFT diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-right.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-right.md index d8426e3e479..c88a2e19266 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-right.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-right.md @@ -23,56 +23,40 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> -## bit_shift_right + ## 描述 -## 语法 +用于 右移 位运算,通常用于将二进制数字的所有位向右移动指定的位数。这种操作通常用于处理二进制数据,或者用于一些数学计算(如除法的高效实现)。 -`BIT_SHIFT_RIGHT(BIGINT x, TINYINT c)` +对 -1 逻辑右移一位得到的结果是 BIGINT_MAX(9223372036854775807)。 -返回对 BIGINT 类型 x 进行逻辑右移 c 位的结果。 +对数字右移负数为得到对结果始终为 0。 -## 举例 -Normal case +## 语法 ```sql -select 1024 as x, number as c, bit_shift_right(1024, number) as bit_shift_right from numbers("number"="5") --------------- - -+------+------+-----------------+ -| x | c | bit_shift_right | -+------+------+-----------------+ -| 1024 | 0 | 1024 | -| 1024 | 1 | 512 | -| 1024 | 2 | 256 | -| 1024 | 3 | 128 | -| 1024 | 4 | 64 | -+------+------+-----------------+ -5 rows in set (0.03 sec) +BIT_SHIFT_RIGHT( <x>, <bits>) ``` -BIGINT -1 逻辑右移一位得到的结果是 BIGINT_MAX -```sql -select bit_shift_right(-1, 1) --------------- -+------------------------+ -| bit_shift_right(-1, 1) | -+------------------------+ -| 9223372036854775807 | -+------------------------+ -``` -如果 c 小于 0 得到的结果始终为 0 -```sql -select bit_shift_right(100, -1) --------------- +## 参数 +| 参数 | 说明 | +|-------|----------------------------------| +| `<x>` | 需要进行位移的数字 | +| `<bits>` | 需要右移的位数。它是一个整数,决定了 `<x>` 将被右移多少位 | -+--------------------------+ -| bit_shift_right(100, -1) | -+--------------------------+ -| 0 | -+--------------------------+ -1 row in set (0.04 sec) -``` +## 返回值 + +返回一个整数,表示右移操作后的结果。 -### keywords +## 举例 - BITSHIFT, BITSHIFTRIGHT +```sql +select BIT_SHIFT_RIGHT(1024,3), BIT_SHIFT_RIGHT(-1,1), BIT_SHIFT_RIGHT(100, -1); +``` + +```text ++--------------------------+------------------------+--------------------------+ +| bit_shift_right(1024, 3) | bit_shift_right(-1, 1) | bit_shift_right(100, -1) | ++--------------------------+------------------------+--------------------------+ +| 128 | 9223372036854775807 | 0 | ++--------------------------+------------------------+--------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-test.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-test.md index 7f9cb7e5f4f..2c53fbad9ce 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-test.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-test.md @@ -24,41 +24,45 @@ specific language governing permissions and limitations under the License. --> -## bit_test + ## 描述 +将`<x>`的值转换为二进制的形式,返回指定位置`<bits>`的值,`<bits>`从0开始,从右到左。 + +如果`<bits>` 有多个值,则将多个`<bits>`位置上的值用与运算符结合起来,返回最终结果。 + +如果`<bits>` 的取值为负数或者超过`<x>`的bit位总数,则会返回结果为0。 + +整数`<x>`范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT。 + +## 别名 +- BIT_TEST_ALL + ## 语法 +```sql +BIT_TEST( <x>, <bits>[, <bits> ... ]) +``` -`bit_test(Integer-type value, Integer-type pos, '......')` +## 参数 +| 参数 | 说明 | +|---------|--------| +| `<x>` | 需计算的整数 | +| `<bits>` | 指定位置的值 | -将value的值转换为二进制的形式,返回指定位置pos的值,pos从0开始,从右到左。 -如果pos 有多个值,则将多个pos位置上的值用与运算符结合起来,返回最终结果。 -如果pos 的取值为负数或者超过value的bit位总数,则会返回结果为0. -整数value范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT +## 返回值 + +返回指定位置的值 ## 举例 -mysql [(none)]>SELECT bit_test(43, 1); -+-----------------+ -| bit_test(43, 1) | -+-----------------+ -| 1 | -+-----------------+ - -mysql [(none)]>select bit_test(43,-1); -+------------------+ -| bit_test(43, -1) | -+------------------+ -| 0 | -+------------------+ - -mysql [(none)]>SELECT bit_test(43, 0, 1, 3, 5,2); -+-----------------------------+ -| bit_test(43, 0, 1, 3, 5, 2) | -+-----------------------------+ -| 0 | -+-----------------------------+ +```sql +select BIT_TEST(43, 1), BIT_TEST(43, -1), BIT_TEST(43, 0, 1, 3, 5,2); ``` -### keywords +```text ++-----------------+------------------+-----------------------------+ +| bit_test(43, 1) | bit_test(43, -1) | bit_test(43, 0, 1, 3, 5, 2) | ++-----------------+------------------+-----------------------------+ +| 1 | 0 | 0 | ++-----------------+------------------+-----------------------------+ +``` - bit_test,bit_test_all diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md index 90cace3f41c..3250af2fa78 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md @@ -22,24 +22,32 @@ specific language governing permissions and limitations under the License. --> -## Description +## 描述 +用于对两个BOOLEAN值进行按位异或操作。 +## 语法 +```sql + <lhs> XOR <rhs> +``` -返回两个数的异或值。 +## 参数 +| 参数 | 说明 | +|-------|--------------| +| `<lhs>` | 参与按位与运算的第一个BOOLEAN值 | +| `<rhs>` | 参与按位与运算的第二个BOOLEAN值 | -## Syntax -`BOOLEAN xor BOOLEAN` +## 返回值 +返回两个BOOLEAN值的异或值。 -## Example +## 示例 ```sql -mysql >select true xor false,true xor true; +select true XOR false,true XOR true; +``` + +```text +------------------+-----------------+ -| (TRUE XOR FALSE) | (TRUE XOR TRUE) | +| xor(TRUE, FALSE) | xor(TRUE, TRUE) | +------------------+-----------------+ | 1 | 0 | +------------------+-----------------+ - ``` - -## Keywords - XOR diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-and.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-and.md index d292aa8cbff..8ae1e8d4d9c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-and.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-and.md @@ -24,34 +24,38 @@ specific language governing permissions and limitations under the License. --> -## bitand ## 描述 +用于执行 按位与(bitwise AND)运算。按位与运算会对两个整数的每一位进行比较,当两个对应的二进制位都为 1 时,结果才为 1,否则为 0。 + +整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT + ## 语法 +```sql +BITAND( <lhs>, <rhs>) +``` -`BITAND(Integer-type lhs, Integer-type rhs)` +## 参数 +| 参数 | 说明 | +|-------|--------------| +| `<lhs>` | 参与按位与运算的第一个数 | +| `<rhs>` | 参与按位与运算的第二个数 | -返回两个整数与运算的结果. +## 返回值 + +返回两个整数与运算的结果。 -整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT ## 举例 -``` -mysql> select bitand(3,5) ans; -+------+ -| ans | -+------+ -| 1 | -+------+ - -mysql> select bitand(4,7) ans; -+------+ -| ans | -+------+ -| 4 | -+------+ +```sql +select BITAND(3,5), BITAND(4,7); ``` -### keywords +```text ++---------+---------+ +| (3 & 5) | (4 & 7) | ++---------+---------+ +| 1 | 4 | ++---------+---------+ - BITAND +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-count.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-count.md index e57863a50b5..ece8fc534ed 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-count.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-count.md @@ -1,7 +1,7 @@ --- { "title": "BIT_COUNT", -"language": "zh-CH" +"language": "zh-CN" } --- @@ -24,29 +24,31 @@ specific language governing permissions and limitations under the License. --> -## bit_count ## 描述 +用于返回一个整数值的二进制表示中 1 的位数。这个函数可以用于快速统计某个整数在二进制表示中 “活跃” 的位数,通常用于分析数据的分布或进行某些位运算 + ## 语法 +```sql +BIT_COUNT( <x>) +``` -`BIT_COUNT(Integer-type x)` +## 参数 +| 参数 | 说明 | +|-------| -- | +| `<x>` | 统计整型 x 的二进制表示中 1 的个数。整型可以是:TINYINT、SMALLINT、INT、BIGINT、LARGEINT | -统计整型 x 的二的补码表示中 1 的个数。 +## 返回值 -整型可以是:TINYINT、SMALLINT、INT、BIGINT、LARGEINT +返回 `<x>` 的二进制表示中 1 的个数 ## 举例 - +```sql +select BIT_COUNT(8), BIT_COUNT(-1); ``` -select "0b11111111", bit_count(-1) --------------- - +```text +--------------+---------------+ -| '0b11111111' | bit_count(-1) | +| bit_count(8) | bit_count(-1) | +--------------+---------------+ -| 0b11111111 | 8 | +| 1 | 8 | +--------------+---------------+ -``` - -### keywords - - BITCOUNT, BIT_COUNT +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md index bc447fb6845..9d595b471e1 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md @@ -24,31 +24,35 @@ specific language governing permissions and limitations under the License. --> -## bit_length ## 描述 + +用于返回一个字符串的 二进制表示 中 位数(即总的二进制位数)。它计算的是字符串的二进制编码所占的位数。 + ## 语法 +```sql +BIT_LENGTH( <str>) +``` -`INT bit_length(VARCHAR str)` +## 参数 +| 参数 | 说明 | +|-------|------------| +| `<str>` | 需计算的字符串 | +## 返回值 -返回字符串的位长度。 +返回 `<str>` 的二进制表示中所占用的位数,包括所有的 0 和 1。 ## 举例 +```sql +select BIT_LENGTH("abc"), BIT_LENGTH("中国"), BIT_LENGTH(123); ``` -mysql> select bit_length("abc"); -+-------------------+ -| bit_length('abc') | -+-------------------+ -| 24 | -+-------------------+ - -mysql> select bit_length("中国"); -+----------------------+ -| bit_length('中国') | -+----------------------+ -| 48 | -+----------------------+ + +```text ++-------------------+----------------------+-----------------------------------------+ +| bit_length('abc') | bit_length('中国') | bit_length(cast(123 as VARCHAR(65533))) | ++-------------------+----------------------+-----------------------------------------+ +| 24 | 48 | 24 | ++-------------------+----------------------+-----------------------------------------+ ``` -### keywords - BIT_LENGTH + diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-not.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-not.md index 9bb726ddd09..783f40949d9 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-not.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-not.md @@ -24,34 +24,32 @@ specific language governing permissions and limitations under the License. --> -## bitnot ## 描述 -## 语法 +用于对整数进行按位取反操作。 -`BITNOT(Integer-type value)` +整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT。 -返回一个整数取反运算的结果. +## 语法 +```sql +BITNOT( <x>) +``` -整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT +## 参数 +| 参数 | 说明 | +|-------|--------| +| `<x>` | 参与运算整数 | -## 举例 +## 返回值 +返回一个整数取反运算的结果 +## 举例 +```sql +select BITNOT(7), BITNOT(-127); ``` -mysql> select bitnot(7) ans; -+------+ -| ans | -+------+ -| -8 | -+------+ - -mysql> select bitxor(-127) ans; -+------+ -| ans | -+------+ -| 126 | -+------+ -``` - -### keywords - - BITNOT +```text ++-------+----------+ +| (~ 7) | (~ -127) | ++-------+----------+ +| -8 | 126 | ++-------+----------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-or.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-or.md index 9c003e8c607..5eccd85c7f0 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-or.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-or.md @@ -24,34 +24,35 @@ specific language governing permissions and limitations under the License. --> -## bitor ## 描述 +用于对两个整数进行按位或操作。 + +整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT + ## 语法 +```sql +BITOR( <lhs>, <rhs>) +``` -`BITOR(Integer-type lhs, Integer-type rhs)` +## 参数 +| 参数 | 说明 | +|-------|--------------| +| `<lhs>` | 参与运算的第一个数 | +| `<rhs>` | 参与运算的第二个数 | -返回两个整数或运算的结果. +## 返回值 -整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT +返回两个整数或运算的结果. ## 举例 - +```sql +select BITOR(3,5), BITOR(4,7); ``` -mysql> select bitor(3,5) ans; -+------+ -| ans | -+------+ -| 7 | -+------+ - -mysql> select bitor(4,7) ans; -+------+ -| ans | -+------+ -| 7 | -+------+ -``` - -### keywords - BITOR +```text ++---------+---------+ +| (3 | 5) | (4 | 7) | ++---------+---------+ +| 7 | 7 | ++---------+---------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-left.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-left.md index eb4bb4966e0..2a8c8ffbc24 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-left.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-left.md @@ -24,48 +24,35 @@ specific language governing permissions and limitations under the License. --> -## bit_shift_left ## 描述 +用于 左移 操作的函数,通常用于执行 位移操作,将二进制数字的所有位向左移动指定的位数。它是位运算的一种形式,常用于处理二进制数据或进行高效的数学计算。 + +对于 BIGINT 类型的最大值 9223372036854775807,进行一位左移的结果将得到 -2。 ## 语法 +```sql +BIT_SHIFT_LEFT( <x>, <bits>) +``` + +## 参数 +| 参数 | 说明 | +|-------|---------------------------------| +| `<x>` | 需要进行位移的数字 | +| `<bits>` | 需要左移的位数。它是一个整数,决定了 `<x>` 将被左移多少位| -`BIT_SHIFT_LEFT(BIGINT x, TINYINT c)` +## 返回值 -将 BIGINT 类型的 x 向左移动 c 位,并将结果作为 BIGINT 返回。 -如果 c 小于 0,则返回零。 +返回一个整数,表示左移操作后的结果。 ## 举例 ```sql -select 8 as x, number as c, bit_shift_left(8, number) as bit_shift_left from numbers("number"="5") --------------- - -+------+------+----------------+ -| x | c | bit_shift_left | -+------+------+----------------+ -| 8 | 0 | 8 | -| 8 | 1 | 16 | -| 8 | 2 | 32 | -| 8 | 3 | 64 | -| 8 | 4 | 128 | -+------+------+----------------+ -5 rows in set (0.04 sec) +select BIT_SHIFT_LEFT(5, 2), BIT_SHIFT_LEFT(-5, 2), BIT_SHIFT_LEFT(9223372036854775807, 1); ``` -对于 BIGINT 类型的最大值 9223372036854775807(即 BIGINT_MAX),进行一位左移的结果将得到 -2。 -```sql -WITH tbl AS ( - SELECT 9223372036854775807 AS BIGINT_MAX -) -SELECT BIGINT_MAX, bit_shift_left(BIGINT_MAX, 1) -FROM tbl --------------- -+---------------------+-------------------------------+ -| BIGINT_MAX | bit_shift_left(BIGINT_MAX, 1) | -+---------------------+-------------------------------+ -| 9223372036854775807 | -2 | -+---------------------+-------------------------------+ -1 row in set (0.05 sec) +```text ++----------------------+-----------------------+----------------------------------------+ +| bit_shift_left(5, 2) | bit_shift_left(-5, 2) | bit_shift_left(9223372036854775807, 1) | ++----------------------+-----------------------+----------------------------------------+ +| 20 | -20 | -2 | ++----------------------+-----------------------+----------------------------------------+ ``` -### keywords - - BITSHIFT, BITSHIFTLEFT diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-right.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-right.md index d8426e3e479..89ffda5e677 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-right.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-right.md @@ -23,56 +23,39 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> -## bit_shift_right + ## 描述 -## 语法 +用于 右移 位运算,通常用于将二进制数字的所有位向右移动指定的位数。这种操作通常用于处理二进制数据,或者用于一些数学计算(如除法的高效实现)。 -`BIT_SHIFT_RIGHT(BIGINT x, TINYINT c)` +对 -1 逻辑右移一位得到的结果是 BIGINT_MAX(9223372036854775807)。 -返回对 BIGINT 类型 x 进行逻辑右移 c 位的结果。 +对数字右移负数为得到对结果始终为 0。 -## 举例 -Normal case +## 语法 ```sql -select 1024 as x, number as c, bit_shift_right(1024, number) as bit_shift_right from numbers("number"="5") --------------- - -+------+------+-----------------+ -| x | c | bit_shift_right | -+------+------+-----------------+ -| 1024 | 0 | 1024 | -| 1024 | 1 | 512 | -| 1024 | 2 | 256 | -| 1024 | 3 | 128 | -| 1024 | 4 | 64 | -+------+------+-----------------+ -5 rows in set (0.03 sec) +BIT_SHIFT_RIGHT( <x>, <bits>) ``` -BIGINT -1 逻辑右移一位得到的结果是 BIGINT_MAX -```sql -select bit_shift_right(-1, 1) --------------- +## 参数 +| 参数 | 说明 | +|-------|----------------------------------| +| `<x>` | 需要进行位移的数字 | +| `<bits>` | 需要右移的位数。它是一个整数,决定了 `<x>` 将被右移多少位 | -+------------------------+ -| bit_shift_right(-1, 1) | -+------------------------+ -| 9223372036854775807 | -+------------------------+ -``` -如果 c 小于 0 得到的结果始终为 0 -```sql -select bit_shift_right(100, -1) --------------- +## 返回值 -+--------------------------+ -| bit_shift_right(100, -1) | -+--------------------------+ -| 0 | -+--------------------------+ -1 row in set (0.04 sec) -``` +返回一个整数,表示右移操作后的结果。 -### keywords +## 举例 - BITSHIFT, BITSHIFTRIGHT +```sql +select BIT_SHIFT_RIGHT(1024,3), BIT_SHIFT_RIGHT(-1,1), BIT_SHIFT_RIGHT(100, -1); +``` + +```text ++--------------------------+------------------------+--------------------------+ +| bit_shift_right(1024, 3) | bit_shift_right(-1, 1) | bit_shift_right(100, -1) | ++--------------------------+------------------------+--------------------------+ +| 128 | 9223372036854775807 | 0 | ++--------------------------+------------------------+--------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-and.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-and.md index d292aa8cbff..8ae1e8d4d9c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-and.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-and.md @@ -24,34 +24,38 @@ specific language governing permissions and limitations under the License. --> -## bitand ## 描述 +用于执行 按位与(bitwise AND)运算。按位与运算会对两个整数的每一位进行比较,当两个对应的二进制位都为 1 时,结果才为 1,否则为 0。 + +整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT + ## 语法 +```sql +BITAND( <lhs>, <rhs>) +``` -`BITAND(Integer-type lhs, Integer-type rhs)` +## 参数 +| 参数 | 说明 | +|-------|--------------| +| `<lhs>` | 参与按位与运算的第一个数 | +| `<rhs>` | 参与按位与运算的第二个数 | -返回两个整数与运算的结果. +## 返回值 + +返回两个整数与运算的结果。 -整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT ## 举例 -``` -mysql> select bitand(3,5) ans; -+------+ -| ans | -+------+ -| 1 | -+------+ - -mysql> select bitand(4,7) ans; -+------+ -| ans | -+------+ -| 4 | -+------+ +```sql +select BITAND(3,5), BITAND(4,7); ``` -### keywords +```text ++---------+---------+ +| (3 & 5) | (4 & 7) | ++---------+---------+ +| 1 | 4 | ++---------+---------+ - BITAND +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-count.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-count.md index e57863a50b5..4770ca9637a 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-count.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-count.md @@ -1,7 +1,7 @@ --- { "title": "BIT_COUNT", -"language": "zh-CH" +"language": "zh-CN" } --- @@ -24,29 +24,32 @@ specific language governing permissions and limitations under the License. --> -## bit_count ## 描述 +用于返回一个整数值的二进制表示中 1 的位数。这个函数可以用于快速统计某个整数在二进制表示中 “活跃” 的位数,通常用于分析数据的分布或进行某些位运算 + ## 语法 +```sql +BIT_COUNT( <x>) +``` -`BIT_COUNT(Integer-type x)` +## 参数 +| 参数 | 说明 | +|-------| -- | +| `<x>` | 统计整型 x 的二进制表示中 1 的个数。整型可以是:TINYINT、SMALLINT、INT、BIGINT、LARGEINT | -统计整型 x 的二的补码表示中 1 的个数。 +## 返回值 -整型可以是:TINYINT、SMALLINT、INT、BIGINT、LARGEINT +返回 `<x>` 的二进制表示中 1 的个数 ## 举例 +```sql +select BIT_COUNT(8), BIT_COUNT(-1); ``` -select "0b11111111", bit_count(-1) --------------- - +```text +--------------+---------------+ -| '0b11111111' | bit_count(-1) | +| bit_count(8) | bit_count(-1) | +--------------+---------------+ -| 0b11111111 | 8 | +| 1 | 8 | +--------------+---------------+ -``` - -### keywords - - BITCOUNT, BIT_COUNT +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md index bc447fb6845..8361e864719 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md @@ -24,31 +24,34 @@ specific language governing permissions and limitations under the License. --> -## bit_length ## 描述 + +用于返回一个字符串的 二进制表示 中 位数(即总的二进制位数)。它计算的是字符串的二进制编码所占的位数。 + ## 语法 +```sql +BIT_LENGTH( <str>) +``` -`INT bit_length(VARCHAR str)` +## 参数 +| 参数 | 说明 | +|-------|------------| +| `<str>` | 需计算的字符串 | +## 返回值 -返回字符串的位长度。 +返回 `<str>` 的二进制表示中所占用的位数,包括所有的 0 和 1。 ## 举例 +```sql +select BIT_LENGTH("abc"), BIT_LENGTH("中国"), BIT_LENGTH(123); ``` -mysql> select bit_length("abc"); -+-------------------+ -| bit_length('abc') | -+-------------------+ -| 24 | -+-------------------+ - -mysql> select bit_length("中国"); -+----------------------+ -| bit_length('中国') | -+----------------------+ -| 48 | -+----------------------+ + +```text ++-------------------+----------------------+-----------------------------------------+ +| bit_length('abc') | bit_length('中国') | bit_length(cast(123 as VARCHAR(65533))) | ++-------------------+----------------------+-----------------------------------------+ +| 24 | 48 | 24 | ++-------------------+----------------------+-----------------------------------------+ ``` -### keywords - BIT_LENGTH diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-not.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-not.md index 9bb726ddd09..783f40949d9 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-not.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-not.md @@ -24,34 +24,32 @@ specific language governing permissions and limitations under the License. --> -## bitnot ## 描述 -## 语法 +用于对整数进行按位取反操作。 -`BITNOT(Integer-type value)` +整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT。 -返回一个整数取反运算的结果. +## 语法 +```sql +BITNOT( <x>) +``` -整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT +## 参数 +| 参数 | 说明 | +|-------|--------| +| `<x>` | 参与运算整数 | -## 举例 +## 返回值 +返回一个整数取反运算的结果 +## 举例 +```sql +select BITNOT(7), BITNOT(-127); ``` -mysql> select bitnot(7) ans; -+------+ -| ans | -+------+ -| -8 | -+------+ - -mysql> select bitxor(-127) ans; -+------+ -| ans | -+------+ -| 126 | -+------+ -``` - -### keywords - - BITNOT +```text ++-------+----------+ +| (~ 7) | (~ -127) | ++-------+----------+ +| -8 | 126 | ++-------+----------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-or.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-or.md index 9c003e8c607..5eccd85c7f0 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-or.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-or.md @@ -24,34 +24,35 @@ specific language governing permissions and limitations under the License. --> -## bitor ## 描述 +用于对两个整数进行按位或操作。 + +整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT + ## 语法 +```sql +BITOR( <lhs>, <rhs>) +``` -`BITOR(Integer-type lhs, Integer-type rhs)` +## 参数 +| 参数 | 说明 | +|-------|--------------| +| `<lhs>` | 参与运算的第一个数 | +| `<rhs>` | 参与运算的第二个数 | -返回两个整数或运算的结果. +## 返回值 -整数范围:TINYINT、SMALLINT、INT、BIGINT、LARGEINT +返回两个整数或运算的结果. ## 举例 - +```sql +select BITOR(3,5), BITOR(4,7); ``` -mysql> select bitor(3,5) ans; -+------+ -| ans | -+------+ -| 7 | -+------+ - -mysql> select bitor(4,7) ans; -+------+ -| ans | -+------+ -| 7 | -+------+ -``` - -### keywords - BITOR +```text ++---------+---------+ +| (3 | 5) | (4 | 7) | ++---------+---------+ +| 7 | 7 | ++---------+---------+ +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-left.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-left.md index eb4bb4966e0..4816597bd08 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-left.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-left.md @@ -24,48 +24,34 @@ specific language governing permissions and limitations under the License. --> -## bit_shift_left ## 描述 +用于 左移 操作的函数,通常用于执行 位移操作,将二进制数字的所有位向左移动指定的位数。它是位运算的一种形式,常用于处理二进制数据或进行高效的数学计算。 + +对于 BIGINT 类型的最大值 9223372036854775807,进行一位左移的结果将得到 -2。 ## 语法 +```sql +BIT_SHIFT_LEFT( <x>, <bits>) +``` + +## 参数 +| 参数 | 说明 | +|-------|---------------------------------| +| `<x>` | 需要进行位移的数字 | +| `<bits>` | 需要左移的位数。它是一个整数,决定了 `<x>` 将被左移多少位 | -`BIT_SHIFT_LEFT(BIGINT x, TINYINT c)` +## 返回值 -将 BIGINT 类型的 x 向左移动 c 位,并将结果作为 BIGINT 返回。 -如果 c 小于 0,则返回零。 +返回一个整数,表示左移操作后的结果。 ## 举例 ```sql -select 8 as x, number as c, bit_shift_left(8, number) as bit_shift_left from numbers("number"="5") --------------- - -+------+------+----------------+ -| x | c | bit_shift_left | -+------+------+----------------+ -| 8 | 0 | 8 | -| 8 | 1 | 16 | -| 8 | 2 | 32 | -| 8 | 3 | 64 | -| 8 | 4 | 128 | -+------+------+----------------+ -5 rows in set (0.04 sec) +select BIT_SHIFT_LEFT(5, 2), BIT_SHIFT_LEFT(-5, 2), BIT_SHIFT_LEFT(9223372036854775807, 1); ``` -对于 BIGINT 类型的最大值 9223372036854775807(即 BIGINT_MAX),进行一位左移的结果将得到 -2。 -```sql -WITH tbl AS ( - SELECT 9223372036854775807 AS BIGINT_MAX -) -SELECT BIGINT_MAX, bit_shift_left(BIGINT_MAX, 1) -FROM tbl --------------- -+---------------------+-------------------------------+ -| BIGINT_MAX | bit_shift_left(BIGINT_MAX, 1) | -+---------------------+-------------------------------+ -| 9223372036854775807 | -2 | -+---------------------+-------------------------------+ -1 row in set (0.05 sec) +```text ++----------------------+-----------------------+----------------------------------------+ +| bit_shift_left(5, 2) | bit_shift_left(-5, 2) | bit_shift_left(9223372036854775807, 1) | ++----------------------+-----------------------+----------------------------------------+ +| 20 | -20 | -2 | ++----------------------+-----------------------+----------------------------------------+ ``` - -### keywords - - BITSHIFT, BITSHIFTLEFT diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-right.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-right.md index d8426e3e479..89ffda5e677 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-right.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-shift-right.md @@ -23,56 +23,39 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> -## bit_shift_right + ## 描述 -## 语法 +用于 右移 位运算,通常用于将二进制数字的所有位向右移动指定的位数。这种操作通常用于处理二进制数据,或者用于一些数学计算(如除法的高效实现)。 -`BIT_SHIFT_RIGHT(BIGINT x, TINYINT c)` +对 -1 逻辑右移一位得到的结果是 BIGINT_MAX(9223372036854775807)。 -返回对 BIGINT 类型 x 进行逻辑右移 c 位的结果。 +对数字右移负数为得到对结果始终为 0。 -## 举例 -Normal case +## 语法 ```sql -select 1024 as x, number as c, bit_shift_right(1024, number) as bit_shift_right from numbers("number"="5") --------------- - -+------+------+-----------------+ -| x | c | bit_shift_right | -+------+------+-----------------+ -| 1024 | 0 | 1024 | -| 1024 | 1 | 512 | -| 1024 | 2 | 256 | -| 1024 | 3 | 128 | -| 1024 | 4 | 64 | -+------+------+-----------------+ -5 rows in set (0.03 sec) +BIT_SHIFT_RIGHT( <x>, <bits>) ``` -BIGINT -1 逻辑右移一位得到的结果是 BIGINT_MAX -```sql -select bit_shift_right(-1, 1) --------------- +## 参数 +| 参数 | 说明 | +|-------|----------------------------------| +| `<x>` | 需要进行位移的数字 | +| `<bits>` | 需要右移的位数。它是一个整数,决定了 `<x>` 将被右移多少位 | -+------------------------+ -| bit_shift_right(-1, 1) | -+------------------------+ -| 9223372036854775807 | -+------------------------+ -``` -如果 c 小于 0 得到的结果始终为 0 -```sql -select bit_shift_right(100, -1) --------------- +## 返回值 -+--------------------------+ -| bit_shift_right(100, -1) | -+--------------------------+ -| 0 | -+--------------------------+ -1 row in set (0.04 sec) -``` +返回一个整数,表示右移操作后的结果。 -### keywords +## 举例 - BITSHIFT, BITSHIFTRIGHT +```sql +select BIT_SHIFT_RIGHT(1024,3), BIT_SHIFT_RIGHT(-1,1), BIT_SHIFT_RIGHT(100, -1); +``` + +```text ++--------------------------+------------------------+--------------------------+ +| bit_shift_right(1024, 3) | bit_shift_right(-1, 1) | bit_shift_right(100, -1) | ++--------------------------+------------------------+--------------------------+ +| 128 | 9223372036854775807 | 0 | ++--------------------------+------------------------+--------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md index 90cace3f41c..dfe28481ddd 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md @@ -22,24 +22,32 @@ specific language governing permissions and limitations under the License. --> -## Description +## 描述 +用于对两个BOOLEAN值进行按位异或操作。 +## 语法 +```sql + <lhs> XOR <rhs> +``` -返回两个数的异或值。 +## 参数 +| 参数 | 说明 | +|-------|--------------| +| `<lhs>` | 参与运算的第一个BOOLEAN值 | +| `<rhs>` | 参与运算的第二个BOOLEAN值 | -## Syntax -`BOOLEAN xor BOOLEAN` +## 返回值 +返回两个BOOLEAN值的异或值。 -## Example +## 示例 ```sql -mysql >select true xor false,true xor true; +select true XOR false,true XOR true; +``` + +```text +------------------+-----------------+ -| (TRUE XOR FALSE) | (TRUE XOR TRUE) | +| xor(TRUE, FALSE) | xor(TRUE, TRUE) | +------------------+-----------------+ | 1 | 0 | +------------------+-----------------+ - ``` - -## Keywords - XOR diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md index d9ccfd4a85c..3595b203afd 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md @@ -24,31 +24,35 @@ specific language governing permissions and limitations under the License. --> -## bit_length -### Description -#### Syntax +## Description -`INT bit_length (VARCHAR str)` +It is used to return the median of the binary representation of a string (that is, the total number of binary digits). It calculates the number of bits occupied by the binary encoding of the string. +## Syntax +```sql +BIT_LENGTH( <str>) +``` + +## Parameters +| parameter | description | +|-----------|-------------| +| `<str>` | The string to be calculated | + +## Return Value -Return length of argument in bits. +Returns the number of bits occupied by `<str>` in the binary representation, including all 0 and 1. -### example +## Examples +```sql +select BIT_LENGTH("abc"), BIT_LENGTH("中国"), BIT_LENGTH(123); ``` -mysql> select bit_length("abc"); -+-------------------+ -| bit_length('abc') | -+-------------------+ -| 24 | -+-------------------+ - -mysql> select bit_length("中国"); -+----------------------+ -| bit_length('中国') | -+----------------------+ -| 48 | -+----------------------+ + +```text ++-------------------+----------------------+-----------------------------------------+ +| bit_length('abc') | bit_length('中国') | bit_length(cast(123 as VARCHAR(65533))) | ++-------------------+----------------------+-----------------------------------------+ +| 24 | 48 | 24 | ++-------------------+----------------------+-----------------------------------------+ ``` -### keywords - BIT_LENGTH + diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitand.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitand.md index 2b22e80945e..7646d17a03d 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitand.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitand.md @@ -24,34 +24,38 @@ specific language governing permissions and limitations under the License. --> -## bitand -### description -#### Syntax +## Description +Used to perform a bitwise AND operation. The bitwise AND operation compares each bit of two integers. The result is 1 only when both corresponding binary bits are 1, otherwise it is 0. -`BITAND(Integer-type lhs, Integer-type rhs)` +Integer range: TINYINT, SMALLINT, INT, BIGINT, LARGEINT -Returns the result of the AND operation of two integers. +## Syntax +```sql +BITAND( <lhs>, <rhs>) +``` -Integer range: TINYINT、SMALLINT、INT、BIGINT、LARGEINT +## Parameters +| parameter | description | +|-----------|--------------| +| `<lhs>` | The first number involved in the bitwise AND operation | +| `<rhs>` | The second number to be included in the bitwise AND operation | -### example +## Return Value -``` -mysql> select bitand(3,5) ans; -+------+ -| ans | -+------+ -| 1 | -+------+ - -mysql> select bitand(4,7) ans; -+------+ -| ans | -+------+ -| 4 | -+------+ +Returns the result of the AND operation on two integers. + + +## Examples + +```sql +select BITAND(3,5), BITAND(4,7); ``` -### keywords +```text ++---------+---------+ +| (3 & 5) | (4 & 7) | ++---------+---------+ +| 1 | 4 | ++---------+---------+ - BITAND +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitcount.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitcount.md index 2518e35f2f1..8ec5798c5f5 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitcount.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitcount.md @@ -24,29 +24,32 @@ specific language governing permissions and limitations under the License. --> -## bit_count -### description -#### Syntax +## Description +Used to return the number of 1 bits in the binary representation of an integer value. This function can be used to quickly count the number of "active" bits of an integer in the binary representation, and is usually used to analyze data distribution or perform certain bit operations -`BIT_COUNT(Integer-type x)` +## Syntax +```sql +BIT_COUNT( <x>) +``` -Returns the exist count of one in 2's complement represent of integer x. +## Parameters +| parameter | description | +|-----------|-----------------------------------------------------------------| +| `<x>` | Counts the number of 1s in the binary representation of integer x. Integer types can be: TINYINT, SMALLINT, INT, BIGINT, LARGEINT | -Integer-type could be: TINYINT、SMALLINT、INT、BIGINT、LARGEINT +## Return Value -### example +Returns the number of 1s in the binary representation of `<x>` -``` -select "0b11111111", bit_count(-1) --------------- +## Examples +```sql +select BIT_COUNT(8), BIT_COUNT(-1); +``` +```text +--------------+---------------+ -| '0b11111111' | bit_count(-1) | +| bit_count(8) | bit_count(-1) | +--------------+---------------+ -| 0b11111111 | 8 | +| 1 | 8 | +--------------+---------------+ ``` - -### keywords - - BITCOUNT, BIT_COUNT diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitnot.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitnot.md index 83464888edf..d6f480079da 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitnot.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitnot.md @@ -24,34 +24,32 @@ specific language governing permissions and limitations under the License. --> -## bitnot -### description -#### Syntax - -`BITNOT(Integer-type value)` - -Returns the result of the NOT operation of one integer. +## Description +Used to perform a bitwise inversion operation on an integer. Integer range: TINYINT、SMALLINT、INT、BIGINT、LARGEINT -### example - -``` -mysql> select bitnot(7) ans; -+------+ -| ans | -+------+ -| -8 | -+------+ - -mysql> select bitxor(-127) ans; -+------+ -| ans | -+------+ -| 126 | -+------+ +## Syntax +```sql +BITNOT( <x>) ``` -### keywords +## Parameters +| parameter | description | +|-----------|-------------| +| `<x>` | Integer operations | + +## Return Value +Returns the result of the NOT operation of one integer. - BITNOT +## Examples +```sql +select BITNOT(7), BITNOT(-127); +``` +```text ++-------+----------+ +| (~ 7) | (~ -127) | ++-------+----------+ +| -8 | 126 | ++-------+----------+ +``` \ No newline at end of file diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitor.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitor.md index 1a9357db7b9..0a2cd82ffe4 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitor.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitor.md @@ -24,34 +24,35 @@ specific language governing permissions and limitations under the License. --> -## bitor -### description -#### Syntax +## Description +Used to perform a bitwise OR operation on two integers. -`BITOR(Integer-type lhs, Integer-type rhs)` +Integer range: TINYINT, SMALLINT, INT, BIGINT, LARGEINT -Returns the result of the OR operation of two integers. +## Syntax +```sql +BITOR( <lhs>, <rhs>) +``` -Integer range: TINYINT、SMALLINT、INT、BIGINT、LARGEINT +## Parameters +| parameter | description | +|-----------|-------------------------------------------------------------------------| +| `<lhs>` | The first BOOLEAN value to be evaluated | +| `<rhs>` | The second BOOLEAN value to be evaluated | -### example +## Return Value -``` -mysql> select bitor(3,5) ans; -+------+ -| ans | -+------+ -| 7 | -+------+ - -mysql> select bitor(4,7) ans; -+------+ -| ans | -+------+ -| 7 | -+------+ -``` +Returns the result of the OR operation on two integers. -### keywords +## Examples +```sql +select BITOR(3,5), BITOR(4,7); +``` - BITOR +```text ++---------+---------+ +| (3 | 5) | (4 | 7) | ++---------+---------+ +| 7 | 7 | ++---------+---------+ +``` \ No newline at end of file diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftleft.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftleft.md index b48313c242b..77e9bd9915c 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftleft.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftleft.md @@ -24,48 +24,34 @@ specific language governing permissions and limitations under the License. --> -## bit_shift_left -### description -#### syntax +## Description +Functions for left shift operations are usually used to perform bit shift operations, which shift all bits of a binary number to the left by a specified number of bits. It is a form of bitwise operation that is often used to process binary data or perform efficient mathematical calculations. -`BIT_SHIFT_LEFT(BIGINT x, TINYINT c)` +For the maximum value of BIGINT type, 9223372036854775807, a one-bit left shift results in -2. +## Syntax +```sql +BIT_SHIFT_LEFT( <x>, <bits>) +``` -Do logical left shift to `BIGINT` type x by c bits, and return result as a `BIGINT`. -Return zero if `c` is less than 0. +## Parameters +| parameter | description | +|-----------|-----------------------------------| +| `<x>` | The number to be shifted | +| `<bits>` |The number of bits to shift left. It is an integer that determines how many bits `<x>` will be shifted left | -### example -Normal case -```sql -select 8 as x, number as c, bit_shift_left(8, number) as bit_shift_left from numbers("number"="5") --------------- +## Return Value -+------+------+----------------+ -| x | c | bit_shift_left | -+------+------+----------------+ -| 8 | 0 | 8 | -| 8 | 1 | 16 | -| 8 | 2 | 32 | -| 8 | 3 | 64 | -| 8 | 4 | 128 | -+------+------+----------------+ -5 rows in set (0.04 sec) -``` -Left shift result of `9223372036854775807` which is `BIGINT_MAX` by 1 bit will get -2. -```sql -WITH tbl AS ( - SELECT 9223372036854775807 AS BIGINT_MAX -) -SELECT BIGINT_MAX, bit_shift_left(BIGINT_MAX, 1) -FROM tbl --------------- +Returns an integer representing the result of a left shift operation. -+---------------------+-------------------------------+ -| BIGINT_MAX | bit_shift_left(BIGINT_MAX, 1) | -+---------------------+-------------------------------+ -| 9223372036854775807 | -2 | -+---------------------+-------------------------------+ -1 row in set (0.05 sec) +## Examples +```sql +select BIT_SHIFT_LEFT(5, 2), BIT_SHIFT_LEFT(-5, 2), BIT_SHIFT_LEFT(9223372036854775807, 1); ``` -### keywords - BITSHIFT, BITSHIFTLEFT +```text ++----------------------+-----------------------+----------------------------------------+ +| bit_shift_left(5, 2) | bit_shift_left(-5, 2) | bit_shift_left(9223372036854775807, 1) | ++----------------------+-----------------------+----------------------------------------+ +| 20 | -20 | -2 | ++----------------------+-----------------------+----------------------------------------+ +``` \ No newline at end of file diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftright.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftright.md index 8d44c3421be..2330a4bc6f4 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftright.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftright.md @@ -24,56 +24,38 @@ specific language governing permissions and limitations under the License. --> -## bit_shift_right -### description -#### syntax +## Description +Used for right shift operations, usually used to shift all bits of a binary number to the right by a specified number of bits. This operation is usually used to process binary data, or for some mathematical calculations (such as efficient implementation of division). -`BIT_SHIFT_RIGHT(BIGINT x, TINYINT c)` +The result of logically shifting -1 right by one position is BIGINT_MAX(9223372036854775807). -Return result of logical right shift of `BIGINT` type x by c bits. +Shifting a number right by a negative amount always results in a result of 0. -### example -Normal case +## Syntax ```sql -select 1024 as x, number as c, bit_shift_right(1024, number) as bit_shift_right from numbers("number"="5") --------------- - -+------+------+-----------------+ -| x | c | bit_shift_right | -+------+------+-----------------+ -| 1024 | 0 | 1024 | -| 1024 | 1 | 512 | -| 1024 | 2 | 256 | -| 1024 | 3 | 128 | -| 1024 | 4 | 64 | -+------+------+-----------------+ -5 rows in set (0.03 sec) +BIT_SHIFT_RIGHT( <x>, <bits>) ``` -Logical right shift `BIGINT` -1 by 1 bits gets `BIGINT_MAX` -```sql -select bit_shift_right(-1, 1) --------------- -+------------------------+ -| bit_shift_right(-1, 1) | -+------------------------+ -| 9223372036854775807 | -+------------------------+ -``` -Return zero if `c` is less than 0 -```sql -select bit_shift_right(100, -1) --------------- +## Parameters +| parameter | description | +|-----------|----------------------------------| +| `<x>` | The number to be shifted | +| `<bits>` | The number of bits to shift right. It is an integer that determines how many bits `<x>` will be shifted right. | -+--------------------------+ -| bit_shift_right(100, -1) | -+--------------------------+ -| 0 | -+--------------------------+ -1 row in set (0.04 sec) -``` +## Return Value +Returns an integer representing the result of a right shift operation. -### keywords +## Examples - BITSHIFT, BITSHIFTRIGHT +```sql +select BIT_SHIFT_RIGHT(1024,3), BIT_SHIFT_RIGHT(-1,1), BIT_SHIFT_RIGHT(100, -1); +``` + +```text ++--------------------------+------------------------+--------------------------+ +| bit_shift_right(1024, 3) | bit_shift_right(-1, 1) | bit_shift_right(100, -1) | ++--------------------------+------------------------+--------------------------+ +| 128 | 9223372036854775807 | 0 | ++--------------------------+------------------------+--------------------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md index d9ccfd4a85c..3595b203afd 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bit-length.md @@ -24,31 +24,35 @@ specific language governing permissions and limitations under the License. --> -## bit_length -### Description -#### Syntax +## Description -`INT bit_length (VARCHAR str)` +It is used to return the median of the binary representation of a string (that is, the total number of binary digits). It calculates the number of bits occupied by the binary encoding of the string. +## Syntax +```sql +BIT_LENGTH( <str>) +``` + +## Parameters +| parameter | description | +|-----------|-------------| +| `<str>` | The string to be calculated | + +## Return Value -Return length of argument in bits. +Returns the number of bits occupied by `<str>` in the binary representation, including all 0 and 1. -### example +## Examples +```sql +select BIT_LENGTH("abc"), BIT_LENGTH("中国"), BIT_LENGTH(123); ``` -mysql> select bit_length("abc"); -+-------------------+ -| bit_length('abc') | -+-------------------+ -| 24 | -+-------------------+ - -mysql> select bit_length("中国"); -+----------------------+ -| bit_length('中国') | -+----------------------+ -| 48 | -+----------------------+ + +```text ++-------------------+----------------------+-----------------------------------------+ +| bit_length('abc') | bit_length('中国') | bit_length(cast(123 as VARCHAR(65533))) | ++-------------------+----------------------+-----------------------------------------+ +| 24 | 48 | 24 | ++-------------------+----------------------+-----------------------------------------+ ``` -### keywords - BIT_LENGTH + diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitand.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitand.md index 2b22e80945e..7646d17a03d 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitand.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitand.md @@ -24,34 +24,38 @@ specific language governing permissions and limitations under the License. --> -## bitand -### description -#### Syntax +## Description +Used to perform a bitwise AND operation. The bitwise AND operation compares each bit of two integers. The result is 1 only when both corresponding binary bits are 1, otherwise it is 0. -`BITAND(Integer-type lhs, Integer-type rhs)` +Integer range: TINYINT, SMALLINT, INT, BIGINT, LARGEINT -Returns the result of the AND operation of two integers. +## Syntax +```sql +BITAND( <lhs>, <rhs>) +``` -Integer range: TINYINT、SMALLINT、INT、BIGINT、LARGEINT +## Parameters +| parameter | description | +|-----------|--------------| +| `<lhs>` | The first number involved in the bitwise AND operation | +| `<rhs>` | The second number to be included in the bitwise AND operation | -### example +## Return Value -``` -mysql> select bitand(3,5) ans; -+------+ -| ans | -+------+ -| 1 | -+------+ - -mysql> select bitand(4,7) ans; -+------+ -| ans | -+------+ -| 4 | -+------+ +Returns the result of the AND operation on two integers. + + +## Examples + +```sql +select BITAND(3,5), BITAND(4,7); ``` -### keywords +```text ++---------+---------+ +| (3 & 5) | (4 & 7) | ++---------+---------+ +| 1 | 4 | ++---------+---------+ - BITAND +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitcount.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitcount.md index 2518e35f2f1..8ec5798c5f5 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitcount.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitcount.md @@ -24,29 +24,32 @@ specific language governing permissions and limitations under the License. --> -## bit_count -### description -#### Syntax +## Description +Used to return the number of 1 bits in the binary representation of an integer value. This function can be used to quickly count the number of "active" bits of an integer in the binary representation, and is usually used to analyze data distribution or perform certain bit operations -`BIT_COUNT(Integer-type x)` +## Syntax +```sql +BIT_COUNT( <x>) +``` -Returns the exist count of one in 2's complement represent of integer x. +## Parameters +| parameter | description | +|-----------|-----------------------------------------------------------------| +| `<x>` | Counts the number of 1s in the binary representation of integer x. Integer types can be: TINYINT, SMALLINT, INT, BIGINT, LARGEINT | -Integer-type could be: TINYINT、SMALLINT、INT、BIGINT、LARGEINT +## Return Value -### example +Returns the number of 1s in the binary representation of `<x>` -``` -select "0b11111111", bit_count(-1) --------------- +## Examples +```sql +select BIT_COUNT(8), BIT_COUNT(-1); +``` +```text +--------------+---------------+ -| '0b11111111' | bit_count(-1) | +| bit_count(8) | bit_count(-1) | +--------------+---------------+ -| 0b11111111 | 8 | +| 1 | 8 | +--------------+---------------+ ``` - -### keywords - - BITCOUNT, BIT_COUNT diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitnot.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitnot.md index 83464888edf..d6f480079da 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitnot.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitnot.md @@ -24,34 +24,32 @@ specific language governing permissions and limitations under the License. --> -## bitnot -### description -#### Syntax - -`BITNOT(Integer-type value)` - -Returns the result of the NOT operation of one integer. +## Description +Used to perform a bitwise inversion operation on an integer. Integer range: TINYINT、SMALLINT、INT、BIGINT、LARGEINT -### example - -``` -mysql> select bitnot(7) ans; -+------+ -| ans | -+------+ -| -8 | -+------+ - -mysql> select bitxor(-127) ans; -+------+ -| ans | -+------+ -| 126 | -+------+ +## Syntax +```sql +BITNOT( <x>) ``` -### keywords +## Parameters +| parameter | description | +|-----------|-------------| +| `<x>` | Integer operations | + +## Return Value +Returns the result of the NOT operation of one integer. - BITNOT +## Examples +```sql +select BITNOT(7), BITNOT(-127); +``` +```text ++-------+----------+ +| (~ 7) | (~ -127) | ++-------+----------+ +| -8 | 126 | ++-------+----------+ +``` \ No newline at end of file diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitor.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitor.md index 1a9357db7b9..0a2cd82ffe4 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitor.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitor.md @@ -24,34 +24,35 @@ specific language governing permissions and limitations under the License. --> -## bitor -### description -#### Syntax +## Description +Used to perform a bitwise OR operation on two integers. -`BITOR(Integer-type lhs, Integer-type rhs)` +Integer range: TINYINT, SMALLINT, INT, BIGINT, LARGEINT -Returns the result of the OR operation of two integers. +## Syntax +```sql +BITOR( <lhs>, <rhs>) +``` -Integer range: TINYINT、SMALLINT、INT、BIGINT、LARGEINT +## Parameters +| parameter | description | +|-----------|-------------------------------------------------------------------------| +| `<lhs>` | The first BOOLEAN value to be evaluated | +| `<rhs>` | The second BOOLEAN value to be evaluated | -### example +## Return Value -``` -mysql> select bitor(3,5) ans; -+------+ -| ans | -+------+ -| 7 | -+------+ - -mysql> select bitor(4,7) ans; -+------+ -| ans | -+------+ -| 7 | -+------+ -``` +Returns the result of the OR operation on two integers. -### keywords +## Examples +```sql +select BITOR(3,5), BITOR(4,7); +``` - BITOR +```text ++---------+---------+ +| (3 | 5) | (4 | 7) | ++---------+---------+ +| 7 | 7 | ++---------+---------+ +``` \ No newline at end of file diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftleft.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftleft.md index b48313c242b..8ebe5b72741 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftleft.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftleft.md @@ -24,48 +24,35 @@ specific language governing permissions and limitations under the License. --> -## bit_shift_left -### description -#### syntax +## Description +Functions for left shift operations are usually used to perform bit shift operations, which shift all bits of a binary number to the left by a specified number of bits. It is a form of bitwise operation that is often used to process binary data or perform efficient mathematical calculations. -`BIT_SHIFT_LEFT(BIGINT x, TINYINT c)` +For the maximum value of BIGINT type, 9223372036854775807, a one-bit left shift results in -2. +## Syntax +```sql +BIT_SHIFT_LEFT( <x>, <bits>) +``` -Do logical left shift to `BIGINT` type x by c bits, and return result as a `BIGINT`. -Return zero if `c` is less than 0. +## Parameters +| parameter | description | +|-----------|-----------------------------------| +| `<x>` | The number to be shifted | +| `<bits>` |The number of bits to shift left. It is an integer that determines how many bits `<x>` will be shifted left | -### example -Normal case -```sql -select 8 as x, number as c, bit_shift_left(8, number) as bit_shift_left from numbers("number"="5") --------------- +## Return Value -+------+------+----------------+ -| x | c | bit_shift_left | -+------+------+----------------+ -| 8 | 0 | 8 | -| 8 | 1 | 16 | -| 8 | 2 | 32 | -| 8 | 3 | 64 | -| 8 | 4 | 128 | -+------+------+----------------+ -5 rows in set (0.04 sec) -``` -Left shift result of `9223372036854775807` which is `BIGINT_MAX` by 1 bit will get -2. +Returns an integer representing the result of a left shift operation. + +## Examples ```sql -WITH tbl AS ( - SELECT 9223372036854775807 AS BIGINT_MAX -) -SELECT BIGINT_MAX, bit_shift_left(BIGINT_MAX, 1) -FROM tbl --------------- +select BIT_SHIFT_LEFT(5, 2), BIT_SHIFT_LEFT(-5, 2), BIT_SHIFT_LEFT(9223372036854775807, 1); +``` -+---------------------+-------------------------------+ -| BIGINT_MAX | bit_shift_left(BIGINT_MAX, 1) | -+---------------------+-------------------------------+ -| 9223372036854775807 | -2 | -+---------------------+-------------------------------+ -1 row in set (0.05 sec) +```text ++----------------------+-----------------------+----------------------------------------+ +| bit_shift_left(5, 2) | bit_shift_left(-5, 2) | bit_shift_left(9223372036854775807, 1) | ++----------------------+-----------------------+----------------------------------------+ +| 20 | -20 | -2 | ++----------------------+-----------------------+----------------------------------------+ ``` -### keywords - BITSHIFT, BITSHIFTLEFT diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftright.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftright.md index 8d44c3421be..2330a4bc6f4 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftright.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/bitshiftright.md @@ -24,56 +24,38 @@ specific language governing permissions and limitations under the License. --> -## bit_shift_right -### description -#### syntax +## Description +Used for right shift operations, usually used to shift all bits of a binary number to the right by a specified number of bits. This operation is usually used to process binary data, or for some mathematical calculations (such as efficient implementation of division). -`BIT_SHIFT_RIGHT(BIGINT x, TINYINT c)` +The result of logically shifting -1 right by one position is BIGINT_MAX(9223372036854775807). -Return result of logical right shift of `BIGINT` type x by c bits. +Shifting a number right by a negative amount always results in a result of 0. -### example -Normal case +## Syntax ```sql -select 1024 as x, number as c, bit_shift_right(1024, number) as bit_shift_right from numbers("number"="5") --------------- - -+------+------+-----------------+ -| x | c | bit_shift_right | -+------+------+-----------------+ -| 1024 | 0 | 1024 | -| 1024 | 1 | 512 | -| 1024 | 2 | 256 | -| 1024 | 3 | 128 | -| 1024 | 4 | 64 | -+------+------+-----------------+ -5 rows in set (0.03 sec) +BIT_SHIFT_RIGHT( <x>, <bits>) ``` -Logical right shift `BIGINT` -1 by 1 bits gets `BIGINT_MAX` -```sql -select bit_shift_right(-1, 1) --------------- -+------------------------+ -| bit_shift_right(-1, 1) | -+------------------------+ -| 9223372036854775807 | -+------------------------+ -``` -Return zero if `c` is less than 0 -```sql -select bit_shift_right(100, -1) --------------- +## Parameters +| parameter | description | +|-----------|----------------------------------| +| `<x>` | The number to be shifted | +| `<bits>` | The number of bits to shift right. It is an integer that determines how many bits `<x>` will be shifted right. | -+--------------------------+ -| bit_shift_right(100, -1) | -+--------------------------+ -| 0 | -+--------------------------+ -1 row in set (0.04 sec) -``` +## Return Value +Returns an integer representing the result of a right shift operation. -### keywords +## Examples - BITSHIFT, BITSHIFTRIGHT +```sql +select BIT_SHIFT_RIGHT(1024,3), BIT_SHIFT_RIGHT(-1,1), BIT_SHIFT_RIGHT(100, -1); +``` + +```text ++--------------------------+------------------------+--------------------------+ +| bit_shift_right(1024, 3) | bit_shift_right(-1, 1) | bit_shift_right(100, -1) | ++--------------------------+------------------------+--------------------------+ +| 128 | 9223372036854775807 | 0 | ++--------------------------+------------------------+--------------------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md index 94e54bde4e5..3f545b437a2 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/bitwise-functions/xor.md @@ -24,34 +24,32 @@ specific language governing permissions and limitations under the License. --> -## bitxor -### description -#### Syntax +## Description +Performs a bitwise exclusive OR operation on two BOOLEAN values. -`BITXOR(Integer-type lhs, Integer-type rhs)` - -Returns the result of the XOR operation of two integers. +## Syntax +```sql + <lhs> XOR <rhs> +``` -Integer range: TINYINT, SMALLINT, INT, BIGINT, LARGEINT +## Parameters +| parameter | description | +|-----------|-------------------------------------------------------------------------| +| `<lhs>` | The first BOOLEAN value to be evaluated | +| `<rhs>` | The second BOOLEAN value to be evaluated | -### example +## Return Value +Returns the exclusive OR of two BOOLEAN values. -``` -mysql> select bitxor(3,5) ans; -+------+ -| ans | -+------+ -| 7 | -+------+ - -mysql> select bitxor(1,7) ans; -+------+ -| ans | -+------+ -| 6 | -+------+ +## Examples +```sql +select true XOR false,true XOR true; ``` -### keywords - - BITXOR +```text ++------------------+-----------------+ +| xor(TRUE, FALSE) | xor(TRUE, TRUE) | ++------------------+-----------------+ +| 1 | 0 | ++------------------+-----------------+ +``` --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org