Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions functions-and-operators/bit-functions-and-operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TiDB 支持使用 MySQL 8.0 中提供的所有[位函数和操作符](https://de
| [`<<`](#左移) | 左移 |
| [`>>`](#右移) | 右移 |

## [`BIT_COUNT()`](https://dev.mysql.com/doc/refman/8.0/en/bit-functions.html#function_bit-count)
## `BIT_COUNT()`

`BIT_COUNT(expr)` 函数返回 `expr` 中为 1 的位数。

Expand Down Expand Up @@ -71,7 +71,7 @@ SELECT BIT_COUNT(INET_ATON('255.255.255.0'));
1 row in set (0.00 sec)
```

## [`&`(按位与)](https://dev.mysql.com/doc/refman/8.0/en/bit-functions.html#operator_bitwise-and)
## `&`(按位与)

`&` 操作符用于执行按位与 (bitwise AND) 操作。它会比较两个数中的对应位,如果两个对应位都是 1,则结果中的对应位为 1,否则为 0。

Expand Down Expand Up @@ -129,7 +129,7 @@ SELECT INET_NTOA(INET_ATON('192.168.1.2') & INET_ATON('255.255.255.0'));
1 row in set (0.00 sec)
```

## [`~`(按位取反)](https://dev.mysql.com/doc/refman/8.0/en/bit-functions.html#operator_bitwise-invert)
## `~`(按位取反)

`~` 操作符用于对给定的值进行按位取反(bitwise NOT)操作。它会对给定值中的每一位进行取反:0 的位变为 1,1 的位变为 0。

Expand Down Expand Up @@ -169,7 +169,7 @@ SELECT CONV(~ b'1111111111111111111111111111111111111111111111110000111100001111
1 row in set (0.00 sec)
```

## [`|`(按位或)](https://dev.mysql.com/doc/refman/8.0/en/bit-functions.html#operator_bitwise-or)
## `|`(按位或)

`|` 操作符用于执行按位或 (bitwise OR) 操作。它会比较两个数中的对应位,如果至少有一个对应位为 1,则结果中的对应位为 1。

Expand Down Expand Up @@ -197,7 +197,7 @@ SELECT CONV(b'1010' | b'1100',10,2);
1 row in set (0.00 sec)
```

## [`^`(按位异或)](https://dev.mysql.com/doc/refman/8.0/en/bit-functions.html#operator_bitwise-xor)
## `^`(按位异或)

`^` 操作符用于执行按位异或 (bitwise XOR) 操作。它会比较两个数中的对应位,如果对应位不同,则结果中的对应位为 1。

Expand Down Expand Up @@ -227,7 +227,7 @@ SELECT CONV(b'1010' ^ b'1100',10,2);

需要注意的是,由于省略了前导零,结果会显示为 `110` 而不是 `0110`。

## [`<<`(左移)](https://dev.mysql.com/doc/refman/8.0/en/bit-functions.html#operator_left-shift)
## `<<`(左移)

`<<` 操作符用于执行左移操作。它会将一个数中的所有位向左移动指定的位数,并用零填充右侧空出的位。

Expand Down Expand Up @@ -261,7 +261,7 @@ SELECT n,1<<n,LPAD(CONV(1<<n,10,2),11,0) FROM cte;
11 rows in set (0.00 sec)
```

## [`>>`(右移)](https://dev.mysql.com/doc/refman/8.0/en/bit-functions.html#operator_right-shift)
## `>>`(右移)

`>>` 操作符用于执行右移操作。它会将数中的所有位向右移动指定的位数,并用零填充左侧空出的位。

Expand Down
24 changes: 12 additions & 12 deletions functions-and-operators/encryption-and-compression-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TiDB 支持使用 MySQL 8.0 中提供的大部分[加密和压缩函数](https:/
| [`UNCOMPRESSED_LENGTH()`](#uncompressed_length) | 返回字符串压缩前的长度 |
| [`VALIDATE_PASSWORD_STRENGTH()`](#validate_password_strength) | 计算密码强度 |

### [`AES_DECRYPT()`](https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_aes-decrypt)
### `AES_DECRYPT()`

`AES_DECRYPT(data, key [,iv])` 函数使用相同的 `key` 解密之前由 [`AES_ENCRYPT()`](#aes_encrypt) 函数加密的 `data`。

Expand All @@ -47,7 +47,7 @@ SELECT AES_DECRYPT(0x28409970815CD536428876175F1A4923, 'secret');
1 row in set (0.00 sec)
```

### [`AES_ENCRYPT()`](https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_aes-encrypt)
### `AES_ENCRYPT()`

`AES_ENCRYPT(data, key [,iv])` 函数使用[高级加密标准 (AES)](https://zh.wikipedia.org/wiki/高级加密标准) 算法和 `key` 加密 `data`。

Expand All @@ -68,7 +68,7 @@ SELECT AES_ENCRYPT(0x616263,'secret');
1 row in set (0.00 sec)
```

### [`COMPRESS()`](https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_compress)
### `COMPRESS()`

`COMPRESS(expr)` 函数返回输入参数 `expr` 的压缩版本。

Expand Down Expand Up @@ -122,7 +122,7 @@ SELECT LENGTH(a),LENGTH(COMPRESS(a)) FROM x;
1 row in set (0.00 sec)
```

### [`MD5()`](https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_md5)
### `MD5()`

`MD5(expr)` 函数为给定参数 `expr` 计算 128 位 [MD5](https://zh.wikipedia.org/wiki/MD5) 哈希值。

Expand All @@ -139,7 +139,7 @@ SELECT MD5('abc');
1 row in set (0.00 sec)
```

### [`PASSWORD()`](https://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html#function_password)
### `PASSWORD()`

> **警告:**
>
Expand All @@ -162,7 +162,7 @@ SELECT PASSWORD('secret');
Warning (Code 1681): PASSWORD is deprecated and will be removed in a future release.
```

### [`RANDOM_BYTES()`](https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_random-bytes)
### `RANDOM_BYTES()`

`RANDOM_BYTES(n)` 函数返回 `n` 个随机字节。

Expand All @@ -179,11 +179,11 @@ SELECT RANDOM_BYTES(3);
1 row in set (0.00 sec)
```

### [`SHA()`](https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_sha1)
### `SHA()`

`SHA()` 函数是 [`SHA1`](#sha1) 的别名。

### [`SHA1()`](https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_sha1)
### `SHA1()`

`SHA1(expr)` 函数为给定参数 `expr` 计算 160 位 [SHA-1](https://zh.wikipedia.org/wiki/SHA-1) 哈希值。

Expand All @@ -200,7 +200,7 @@ SELECT SHA1('abc');
1 row in set (0.00 sec)
```

### [`SHA2()`](https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_sha2)
### `SHA2()`

`SHA2(str, n)` 函数使用 [SHA-2](https://zh.wikipedia.org/wiki/SHA-2) 系列中的算法计算哈希值。参数 `n` 用于选择算法。如果任一参数为 `NULL` 或 `n` 指定的算法未知或不受支持,`SHA2()` 返回 `NULL`。

Expand Down Expand Up @@ -248,7 +248,7 @@ SELECT SM3('abc');
1 row in set (0.00 sec)
```

### [`UNCOMPRESS()`](https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_uncompress)
### `UNCOMPRESS()`

`UNCOMPRESS(data)` 函数解压缩使用 [`COMPRESS()`](#compress) 函数压缩的数据。

Expand All @@ -265,7 +265,7 @@ SELECT UNCOMPRESS(0x03000000789C72747206040000FFFF018D00C7);
1 row in set (0.00 sec)
```

### [`UNCOMPRESSED_LENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_uncompressed-length)
### `UNCOMPRESSED_LENGTH()`

`UNCOMPRESSED_LENGTH(data)` 函数返回压缩数据的前 4 个字节,即字符串在使用 [`COMPRESS()`](#compress) 函数压缩之前的长度。

Expand All @@ -282,7 +282,7 @@ SELECT UNCOMPRESSED_LENGTH(0x03000000789C72747206040000FFFF018D00C7);
1 row in set (0.00 sec)
```

### [`VALIDATE_PASSWORD_STRENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_validate-password-strength)
### `VALIDATE_PASSWORD_STRENGTH()`

`VALIDATE_PASSWORD_STRENGTH(str)` 函数用作 [TiDB 密码管理](/password-management.md)的一部分,它计算密码的强度并返回一个 0 到 100 之间的整数值。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ summary: 了解聚合 JSON 值的 JSON 函数。

本文档介绍 TiDB [聚合函数](/functions-and-operators/aggregate-group-by-functions.md) 中专门用于处理 JSON 的聚合函数。

## [JSON_ARRAYAGG()](https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_json-arrayagg)
TiDB 支持使用 MySQL 8.0 中提供的[两个 JSON 聚合函数](https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html)。

## `JSON_ARRAYAGG()`

`JSON_ARRAYAGG(key)` 函数可以根据给定的 `key` 将 `key` 值聚合到一个 JSON 数组中。`key` 通常为表达式或列名。

Expand All @@ -28,7 +30,7 @@ SELECT JSON_ARRAYAGG(v) FROM (SELECT 1 'v' UNION SELECT 2);
1 row in set (0.00 sec)
```

## [JSON_OBJECTAGG()](https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_json-objectagg)
## `JSON_OBJECTAGG()`

`JSON_OBJECTAGG(key,value)` 函数可以根据给定的 `key` 和 `value` 将 `key` 值和 `value` 值聚合成一个 JSON 对象。`key` 和 `value` 通常为表达式或列名。

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ summary: 了解创建 JSON 值的 JSON 函数。

# 创建 JSON 值的 JSON 函数

本文档介绍用于创建 JSON 值的 JSON 函数。
TiDB 支持使用 MySQL 8.0 中提供的所有[用于创建 JSON 值的 JSON 函数](https://dev.mysql.com/doc/refman/8.0/en/json-creation-functions.html)

## [JSON_ARRAY()](https://dev.mysql.com/doc/refman/8.0/en/json-creation-functions.html#function_json-array)
## `JSON_ARRAY()`

`JSON_ARRAY([val[, val] ...])` 函数接受一个值列表(可能为空)作为参数,并返回一个包含这些值的 JSON 数组。

Expand All @@ -24,7 +24,7 @@ SELECT JSON_ARRAY(1,2,3,4,5), JSON_ARRAY("foo", "bar");
1 row in set (0.00 sec)
```

## [JSON_OBJECT()](https://dev.mysql.com/doc/refman/8.0/en/json-creation-functions.html#function_json-object)
## `JSON_OBJECT()`

`JSON_OBJECT([key,val[,key,val]...])` 函数接受一个键值对列表(可能为空)作为参数,并返回一个包含这些键值对的 JSON 对象。

Expand All @@ -41,7 +41,7 @@ SELECT JSON_OBJECT("database", "TiDB", "distributed", TRUE);
1 row in set (0.00 sec)
```

## [JSON_QUOTE()](https://dev.mysql.com/doc/refman/8.0/en/json-creation-functions.html#function_json-quote)
## `JSON_QUOTE()`

`JSON_QUOTE(str)` 函数将字符串返回为带引号的 JSON 值。

Expand Down
24 changes: 12 additions & 12 deletions functions-and-operators/json-functions/json-functions-modify.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ summary: 了解修改 JSON 值的 JSON 函数。

# 修改 JSON 值的 JSON 函数

本文档介绍用于修改 JSON 值的 JSON 函数。
TiDB 支持使用 MySQL 8.0 中提供的所有[用于修改 JSON 值的 JSON 函数](https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html)

## [JSON_APPEND()](https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-append)
## `JSON_APPEND()`

该函数为 [`JSON_ARRAY_APPEND()`](#json_array_append) 的别名。

## [JSON_ARRAY_APPEND()](https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-array-append)
## `JSON_ARRAY_APPEND()`

`JSON_ARRAY_APPEND(json_array, path, value [,path, value] ...)` 函数将 `value` 插入 `path` 中指定的 `json_array` 数组的末尾,并返回结果。

Expand Down Expand Up @@ -49,7 +49,7 @@ SELECT JSON_ARRAY_APPEND('{"transport_options": ["Car", "Boat", "Train"]}', '$.t
1 row in set (0.00 sec)
```

## [JSON_ARRAY_INSERT()](https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-array-insert)
## `JSON_ARRAY_INSERT()`

`JSON_ARRAY_INSERT(json_array, path, value [,path, value] ...)` 函数将 `value` 插入 `path` 中 `json_array` 的指定位置,并返回结果。

Expand Down Expand Up @@ -87,7 +87,7 @@ SELECT JSON_ARRAY_INSERT('["Car", "Boat", "Train"]', '$[1]', "Airplane") AS "Tra
1 row in set (0.00 sec)
```

## [JSON_INSERT()](https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-insert)
## `JSON_INSERT()`

`JSON_INSERT(json_doc,path,value[,path,value] ...)` 函数将一个或多个值插入到 JSON 文档,并返回结果。

Expand Down Expand Up @@ -125,7 +125,7 @@ SELECT JSON_INSERT('{"a": 61, "b": 62}', '$.a', 41, '$.c', 63);
1 row in set (0.00 sec)
```

## [JSON_MERGE_PATCH()](https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-merge-patch)
## `JSON_MERGE_PATCH()`

`JSON_MERGE_PATCH(json_doc, json_doc [,json_doc] ...)` 将两个或多个 JSON 文档合并为一个 JSON 文档,但不保留重复键的值。如果其中某些 `json_doc` 参数包含重复的键,合并后的结果只保留后面指定的那个 `json_doc` 参数中的值。

Expand All @@ -150,7 +150,7 @@ SELECT JSON_MERGE_PATCH(
1 row in set (0.00 sec)
```

## [JSON_MERGE_PRESERVE()](https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-merge-preserve)
## `JSON_MERGE_PRESERVE()`

`JSON_MERGE_PRESERVE(json_doc, json_doc [,json_doc] ...)` 函数通过保留所有键值的方式合并两个或多个 JSON 文档,并返回合并结果。

Expand All @@ -171,15 +171,15 @@ SELECT JSON_MERGE_PRESERVE('{"a": 1, "b": 2}','{"a": 100}', '{"c": 300}');
1 row in set (0.00 sec)
```

## [JSON_MERGE()](https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-merge)
## `JSON_MERGE()`

> **警告:**
>
> 该函数已废弃。

该函数为 [`JSON_MERGE_PRESERVE()`](#json_merge_preserve) 已废弃的别名。

## [JSON_REMOVE()](https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-remove)
## `JSON_REMOVE()`

`JSON_REMOVE(json_doc,path [,path] ...)` 函数从 JSON 文档中删除指定 `path` 的数据并返回结果。

Expand Down Expand Up @@ -215,7 +215,7 @@ SELECT JSON_REMOVE('{"a": 61, "b": 62, "c": 63}','$.b','$.c');
1 row in set (0.00 sec)
```

## [JSON_REPLACE()](https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-replace)
## `JSON_REPLACE()`

`JSON_REPLACE(json_doc,path,value[,path,value]...)` 函数替换 JSON 文档中的现有的值并返回结果。如果指定的路径不存在,该路径对应的值不会添加到结果中。

Expand Down Expand Up @@ -253,7 +253,7 @@ SELECT JSON_REPLACE('{"a": 41, "b": 62}','$.b',42,'$.c',43);
1 row in set (0.00 sec)
```

## [JSON_SET()](https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-set)
## `JSON_SET()`

`JSON_SET(json_doc,path,value[,path,value] ...)` 函数在 JSON 文档中插入或更新数据,并返回结果。

Expand Down Expand Up @@ -291,7 +291,7 @@ SELECT JSON_SET('{"version": 1.1, "name": "example"}','$.version',1.2,'$.branch'
1 row in set (0.00 sec)
```

## [JSON_UNQUOTE()](https://dev.mysql.com/doc/refman/8.0/en/json-modification-functions.html#function_json-unquote)
## `JSON_UNQUOTE()`

`JSON_UNQUOTE(json)` 函数去掉 JSON 值的引号,并以字符串形式返回结果。该函数与 [`JSON_QUOTE()`](/functions-and-operators/json-functions/json-functions-create.md#json_quote) 函数作用相反。

Expand Down
10 changes: 5 additions & 5 deletions functions-and-operators/json-functions/json-functions-return.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ summary: 了解返回 JSON 值的 JSON 函数。

# 返回 JSON 值的 JSON 函数

本文介绍返回 JSON 值的 JSON 函数。
TiDB 支持使用 MySQL 8.0 中提供的所有[用于返回 JSON 值属性的 JSON 函数](https://dev.mysql.com/doc/refman/8.0/en/json-attribute-functions.html)

## [JSON_DEPTH()](https://dev.mysql.com/doc/refman/8.0/en/json-attribute-functions.html#function_json-depth)
## `JSON_DEPTH()`

`JSON_DEPTH(json_doc)` 函数返回 JSON 文档的最大深度。

Expand All @@ -32,7 +32,7 @@ SELECT JSON_DEPTH('{"weather": {"current": "sunny"}}');
1 row in set (0.00 sec)
```

## [JSON_LENGTH()](https://dev.mysql.com/doc/refman/8.0/en/json-attribute-functions.html#function_json-length)
## `JSON_LENGTH()`

`JSON_LENGTH(json_doc [,path])` 函数返回 JSON 文档的长度。如果指定了 `path` 参数,则返回路径中的值的长度。

Expand Down Expand Up @@ -68,7 +68,7 @@ SELECT JSON_LENGTH('{"weather": {"current": "sunny", "tomorrow": "cloudy"}}','$.
1 row in set (0.01 sec)
```

## [JSON_TYPE()](https://dev.mysql.com/doc/refman/8.0/en/json-attribute-functions.html#function_json-type)
## `JSON_TYPE()`

`JSON_TYPE(json_val)` 函数返回一个字符串,表示 [JSON 值的类型](/data-type-json.md#json-值的类型)。

Expand Down Expand Up @@ -132,7 +132,7 @@ SELECT JSON_TYPE('"2025-06-14"'),JSON_TYPE(CAST(CAST('2025-06-14' AS date) AS js
1 row in set (0.00 sec)
```

## [JSON_VALID()](https://dev.mysql.com/doc/refman/8.0/en/json-attribute-functions.html#function_json-valid)
## `JSON_VALID()`

`JSON_VALID(str)` 函数检查输入的参数是否为有效的 JSON 格式。该函数对于在将列转换为 `JSON` 类型之前进行检查非常有用。

Expand Down
Loading