From bc4f6b8a79845b6da49ea214b717a48a238b6aae Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 17 Nov 2025 17:26:01 +0800 Subject: [PATCH 1/4] Add temp.md --- temp.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 temp.md diff --git a/temp.md b/temp.md new file mode 100644 index 000000000000..af27ff4986a7 --- /dev/null +++ b/temp.md @@ -0,0 +1 @@ +This is a test file. \ No newline at end of file From 754a8eeafe67ca36c59414c157c3fd701d63d113 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 17 Nov 2025 17:26:06 +0800 Subject: [PATCH 2/4] Delete temp.md --- temp.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 temp.md diff --git a/temp.md b/temp.md deleted file mode 100644 index af27ff4986a7..000000000000 --- a/temp.md +++ /dev/null @@ -1 +0,0 @@ -This is a test file. \ No newline at end of file From 95d2db427cedeeb67f589fb734257573245ca4bb Mon Sep 17 00:00:00 2001 From: qiancai Date: Mon, 17 Nov 2025 17:43:26 +0800 Subject: [PATCH 3/4] add translation --- .../bit-functions-and-operators.md | 14 +-- .../encryption-and-compression-functions.md | 24 ++-- .../json-functions-aggregate.md | 6 +- .../json-functions/json-functions-create.md | 8 +- .../json-functions/json-functions-modify.md | 24 ++-- .../json-functions/json-functions-return.md | 10 +- .../json-functions/json-functions-search.md | 20 +-- .../json-functions/json-functions-utility.md | 8 +- .../json-functions/json-functions-validate.md | 4 +- functions-and-operators/string-functions.md | 116 +++++++++--------- functions-and-operators/window-functions.md | 22 ++-- 11 files changed, 129 insertions(+), 127 deletions(-) diff --git a/functions-and-operators/bit-functions-and-operators.md b/functions-and-operators/bit-functions-and-operators.md index f7725626db66..72b74e86e903 100644 --- a/functions-and-operators/bit-functions-and-operators.md +++ b/functions-and-operators/bit-functions-and-operators.md @@ -19,7 +19,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 的位数。 @@ -70,7 +70,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。 @@ -128,7 +128,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。 @@ -168,7 +168,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。 @@ -196,7 +196,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。 @@ -226,7 +226,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) +## `<<`(左移) `<<` 操作符用于执行左移操作。它会将一个数中的所有位向左移动指定的位数,并用零填充右侧空出的位。 @@ -260,7 +260,7 @@ SELECT n,1<>`(右移)](https://dev.mysql.com/doc/refman/8.0/en/bit-functions.html#operator_right-shift) +## `>>`(右移) `>>` 操作符用于执行右移操作。它会将数中的所有位向右移动指定的位数,并用零填充左侧空出的位。 diff --git a/functions-and-operators/encryption-and-compression-functions.md b/functions-and-operators/encryption-and-compression-functions.md index 2b55a9dc243e..ea7f56579864 100644 --- a/functions-and-operators/encryption-and-compression-functions.md +++ b/functions-and-operators/encryption-and-compression-functions.md @@ -25,7 +25,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`。 @@ -46,7 +46,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`。 @@ -67,7 +67,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` 的压缩版本。 @@ -121,7 +121,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) 哈希值。 @@ -138,7 +138,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()` > **警告:** > @@ -161,7 +161,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` 个随机字节。 @@ -178,11 +178,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) 哈希值。 @@ -199,7 +199,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`。 @@ -247,7 +247,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) 函数压缩的数据。 @@ -264,7 +264,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) 函数压缩之前的长度。 @@ -281,7 +281,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 之间的整数值。 diff --git a/functions-and-operators/json-functions/json-functions-aggregate.md b/functions-and-operators/json-functions/json-functions-aggregate.md index a419676cc506..7c396cf4cf89 100644 --- a/functions-and-operators/json-functions/json-functions-aggregate.md +++ b/functions-and-operators/json-functions/json-functions-aggregate.md @@ -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/json-aggregation-functions.html)。 + +## `JSON_ARRAYAGG()` `JSON_ARRAYAGG(key)` 函数可以根据给定的 `key` 将 `key` 值聚合到一个 JSON 数组中。`key` 通常为表达式或列名。 @@ -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` 通常为表达式或列名。 diff --git a/functions-and-operators/json-functions/json-functions-create.md b/functions-and-operators/json-functions/json-functions-create.md index fc8d3b3faa2f..60a9b52aead0 100644 --- a/functions-and-operators/json-functions/json-functions-create.md +++ b/functions-and-operators/json-functions/json-functions-create.md @@ -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 数组。 @@ -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 对象。 @@ -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 值。 diff --git a/functions-and-operators/json-functions/json-functions-modify.md b/functions-and-operators/json-functions/json-functions-modify.md index 2f4f170c5759..c45fc0888ada 100644 --- a/functions-and-operators/json-functions/json-functions-modify.md +++ b/functions-and-operators/json-functions/json-functions-modify.md @@ -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` 数组的末尾,并返回结果。 @@ -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` 的指定位置,并返回结果。 @@ -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 文档,并返回结果。 @@ -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` 参数中的值。 @@ -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 文档,并返回合并结果。 @@ -171,7 +171,7 @@ 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()` > **警告:** > @@ -179,7 +179,7 @@ SELECT JSON_MERGE_PRESERVE('{"a": 1, "b": 2}','{"a": 100}', '{"c": 300}'); 该函数为 [`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` 的数据并返回结果。 @@ -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 文档中的现有的值并返回结果。如果指定的路径不存在,该路径对应的值不会添加到结果中。 @@ -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 文档中插入或更新数据,并返回结果。 @@ -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) 函数作用相反。 diff --git a/functions-and-operators/json-functions/json-functions-return.md b/functions-and-operators/json-functions/json-functions-return.md index 9adb89071d6b..ee849d57570e 100644 --- a/functions-and-operators/json-functions/json-functions-return.md +++ b/functions-and-operators/json-functions/json-functions-return.md @@ -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 文档的最大深度。 @@ -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` 参数,则返回路径中的值的长度。 @@ -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-值的类型)。 @@ -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` 类型之前进行检查非常有用。 diff --git a/functions-and-operators/json-functions/json-functions-search.md b/functions-and-operators/json-functions/json-functions-search.md index ee9d4e626b61..9cbe6f88e93f 100644 --- a/functions-and-operators/json-functions/json-functions-search.md +++ b/functions-and-operators/json-functions/json-functions-search.md @@ -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-search-functions.html)。 -## [JSON_CONTAINS()](https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#function_json-contains) +## `JSON_CONTAINS()` 通过返回 `1` 或 `0`,`JSON_CONTAINS(json_doc, candidate [,path])` 函数用于确认指定的 JSON 文档 `candidate` 是否包含在目标 JSON 文档中。 @@ -88,7 +88,7 @@ SELECT JSON_CONTAINS('{"foo": "bar", "aaa": 5}','"bar"', '$.foo'); 1 row in set (0.00 sec) ``` -## [JSON_CONTAINS_PATH()](https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#function_json-contains-path) +## `JSON_CONTAINS_PATH()` `JSON_CONTAINS_PATH(json_doc,all_or_one,path [,path, ...])` 函数返回 `0` 或 `1`,表示 JSON 文档是否包含指定路径下的数据。 @@ -139,7 +139,7 @@ SELECT JSON_CONTAINS_PATH('{"foo": "bar", "aaa": 5}','all','$.foo', '$.aaa'); 1 row in set (0.00 sec) ``` -## [JSON_EXTRACT()](https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#function_json-extract) +## `JSON_EXTRACT()` `JSON_EXTRACT(json_doc, path[, path] ...)` 函数从 JSON 文档中提取与 `path` 参数匹配的数据。 @@ -156,7 +156,7 @@ SELECT JSON_EXTRACT('{"foo": "bar", "aaa": 5}', '$.foo'); 1 row in set (0.00 sec) ``` -## [->](https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#operator_json-column-path) +## `->` `column->path` 函数返回 `column` 中与 `path` 参数匹配的数据。该函数是 [`JSON_EXTRACT()`](#json_extract) 的别名。 @@ -179,7 +179,7 @@ FROM ( 1 row in set (0.00 sec) ``` -## [->>](https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#operator_json-inline-path) +## `->>` `column->>path` 函数去掉 `column` 中与 `path` 参数匹配的数据的引号。它是 `JSON_UNQUOTE(JSON_EXTRACT(doc,path_literal))` 的别名。 @@ -204,7 +204,7 @@ FROM ( 1 row in set (0.00 sec) ``` -## [JSON_KEYS()](https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#function_json-keys) +## `JSON_KEYS()` `JSON_KEYS(json_doc [,path])` 函数以 JSON 数组的形式返回 JSON 对象的顶层键 (key)。如果指定了 `path` 参数,则返回所选路径的顶层键 (key)。 @@ -240,7 +240,7 @@ SELECT JSON_KEYS('{"name": {"first": "John", "last": "Doe"}, "type": "Person"}', 1 row in set (0.00 sec) ``` -## [JSON_SEARCH()](https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#function_json-search) +## `JSON_SEARCH()` `JSON_SEARCH(json_doc,one_or_all,str)` 函数会在 JSON 文档中搜索与字符串匹配的一个或所有的匹配项。 @@ -276,7 +276,7 @@ SELECT JSON_SEARCH('{"a": ["aa", "bb", "cc"], "b": ["cc", "dd"]}','all','cc'); 1 row in set (0.01 sec) ``` -## [MEMBER OF()](https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#operator_member-of) +## `MEMBER OF()` `str MEMBER OF (json_array)` 函数测试传入的 `str` 值是否是 `json_array` 的元素,如果是则返回 `1`,否则返回 `0`。如果任一参数为 `NULL`,则返回 `NULL`。 @@ -294,7 +294,7 @@ SELECT '🍍' MEMBER OF ('["🍍","🥥","🥭"]') AS 'Contains pineapple'; ``` -## [JSON_OVERLAPS()](https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html#function_json-overlaps) +## `JSON_OVERLAPS()` `JSON_OVERLAPS(json_doc, json_doc)` 函数检查两个 JSON 文档是否有重叠部分。如果有重叠,则返回 `1`,如果没有重叠,则返回 `0`。如果任一参数为 `NULL`,则返回 `NULL`。 diff --git a/functions-and-operators/json-functions/json-functions-utility.md b/functions-and-operators/json-functions/json-functions-utility.md index 3c60681b006f..64e68a758155 100644 --- a/functions-and-operators/json-functions/json-functions-utility.md +++ b/functions-and-operators/json-functions/json-functions-utility.md @@ -5,9 +5,9 @@ summary: 了解 JSON 效用函数。 # JSON 效用函数 -本文档介绍 JSON 效用函数。 +TiDB 支持使用 MySQL 8.0 中提供的所有[JSON 效用函数](https://dev.mysql.com/doc/refman/8.0/en/json-utility-functions.html)。 -## [JSON_PRETTY()](https://dev.mysql.com/doc/refman/8.0/en/json-utility-functions.html#function_json-pretty) +## `JSON_PRETTY()` `JSON_PRETTY(json_doc)` 函数用于格式化 JSON 文档。 @@ -29,7 +29,7 @@ JSON_PRETTY('{"person":{"name":{"first":"John","last":"Doe"},"age":23}}'): { 1 row in set (0.00 sec) ``` -## [JSON_STORAGE_FREE()](https://dev.mysql.com/doc/refman/8.0/en/json-utility-functions.html#function_json-storage-free) +## `JSON_STORAGE_FREE()` `JSON_STORAGE_FREE(json_doc)` 函数返回 JSON 值在原地更新操作后释放了多少存储空间,以二进制表示。 @@ -50,7 +50,7 @@ SELECT JSON_STORAGE_FREE('{}'); 1 row in set (0.00 sec) ``` -## [JSON_STORAGE_SIZE()](https://dev.mysql.com/doc/refman/8.0/en/json-utility-functions.html#function_json-storage-size) +## `JSON_STORAGE_SIZE()` `JSON_STORAGE_SIZE(json_doc)` 函数返回存储 JSON 值所需的大致字节数。由于计算该大小时不考虑 TiKV 对数据的压缩,因此该函数的输出与 MySQL 并不完全兼容。 diff --git a/functions-and-operators/json-functions/json-functions-validate.md b/functions-and-operators/json-functions/json-functions-validate.md index cde80373a5d8..5daffc740e9e 100644 --- a/functions-and-operators/json-functions/json-functions-validate.md +++ b/functions-and-operators/json-functions/json-functions-validate.md @@ -5,9 +5,9 @@ summary: 了解验证 JSON 文档的函数。 # 验证 JSON 文档的函数 -本文档介绍用于验证 JSON 文档的函数。 +TiDB 支持使用 MySQL 8.0 中提供的大部分[用于验证 JSON 文档的 JSON 函数](https://dev.mysql.com/doc/refman/8.0/en/json-validation-functions.html)。 -## [JSON_SCHEMA_VALID()](https://dev.mysql.com/doc/refman/8.0/en/json-validation-functions.html#function_json-schema-valid) +## `JSON_SCHEMA_VALID()` `JSON_SCHEMA_VALID(schema, json_doc)` 函数根据 schema 验证 JSON 文档,确保数据的完整性和一致性。该函数可以与 [CHECK](/constraints.md#check-约束) 约束一起使用,以便在修改表时自动进行 schema 验证。该函数遵循 [JSON Schema specification](https://json-schema.org/specification)。 diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 03869f94796e..ab1649cd8222 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -11,7 +11,7 @@ TiDB 支持使用 MySQL 8.0 中提供的大部分[字符串函数](https://dev.m ## 支持的函数 -### [`ASCII()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_ascii) +### `ASCII()` `ASCII()` 函数用于获取输入的参数中最左字符的 ASCII 值。该参数可以为字符串或数字。 @@ -39,7 +39,7 @@ SELECT ASCII('A'), ASCII('TiDB'), ASCII(23); +------------+---------------+-----------+ ``` -### [`BIN()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_bin) +### `BIN()` `BIN()` 函数用于将输入的参数转换为其二进制值的字符串表示形式。该参数可以为字符串或数字。 @@ -82,7 +82,7 @@ SELECT BIN(-7); +------------------------------------------------------------------+ ``` -### [`BIT_LENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_bit-length) +### `BIT_LENGTH()` `BIT_LENGTH()` 函数用于返回输入参数的长度,单位为 bit。 @@ -127,7 +127,7 @@ SELECT CustomerName, BIT_LENGTH(CustomerName) AS BitLengthOfName FROM Customers; > > 上面这个示例假设数据库中存在一个名为 `Customers` 的表,表中有一个名为 `CustomerName` 的列。 -### [`CHAR()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_char) +### `CHAR()` `CHAR()` 函数用于获取指定 ASCII 值的对应字符。该函数执行的操作与 `ASCII()` 相反,`ASCII()` 用于返回指定字符的 ASCII 值。如果提供了多个参数,`CHAR()` 函数将作用于所有参数并将它们的结果拼接在一起返回。 @@ -196,7 +196,7 @@ SELECT CHAR(65,66,67); 1 row in set (0.00 sec) ``` -### [`CHAR_LENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_char-length) +### `CHAR_LENGTH()` `CHAR_LENGTH()` 函数用于获取输入参数中字符的总数。 @@ -227,11 +227,11 @@ SELECT CustomerName, CHAR_LENGTH(CustomerName) AS LengthOfName FROM Customers; > > 上面这个示例假设数据库中存在一个名为 `Customers` 的表,表中有一个名为 `CustomerName` 的列。 -### [`CHARACTER_LENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_character-length) +### `CHARACTER_LENGTH()` `CHARACTER_LENGTH()` 函数与 `CHAR_LENGTH()` 函数功能相同,返回结果相同,可以互换使用。 -### [`CONCAT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_concat) +### `CONCAT()` `CONCAT()` 函数用于将输入的参数连接成一个字符串。 @@ -293,7 +293,7 @@ SELECT 'Ti' 'DB' ' ' 'Server'; +-------------+ ``` -### [`CONCAT_WS()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_concat-ws) +### `CONCAT_WS()` `CONCAT_WS()` 函数是一种带分隔符的 [`CONCAT()`](#concat),返回由分隔符连接的字符串。 @@ -412,7 +412,7 @@ SELECT CONCAT_WS(',', 'TiDB Server', 'TiKV', 'PD'); +-----------------------------------------+ ``` -### [`ELT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_elt) +### `ELT()` `ELT()` 函数返回索引号对应的元素。 @@ -431,7 +431,7 @@ SELECT ELT(3, 'This', 'is', 'TiDB'); 在以上示例中,该函数返回第三个元素,即 `'TiDB'`。 -### [`EXPORT_SET()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_export-set) +### `EXPORT_SET()` `EXPORT_SET()` 函数返回一个由指定数量 (`number_of_bits`) 的 `on`/`off` 值组成的字符串,各个值之间可以用 `separator` 分隔(可选)。这些值将基于输入的 `bits` 参数中的相应 bit 是否为 `1` 而确定,其中第一个值对应于 `bits` 中的最右边(即最低)的 bit。 @@ -494,7 +494,7 @@ SELECT EXPORT_SET(b'01010101', 'x', '_', '', 8); 1 row in set (0.00 sec) ``` -### [`FIELD()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_field) +### `FIELD()` 返回参数在后续参数中出现的第一个位置 @@ -510,7 +510,7 @@ SELECT FIELD('needle', 'A', 'needle', 'in', 'a', 'haystack'); 1 row in set (0.00 sec) ``` -### [`FIND_IN_SET()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_find-in-set) +### `FIND_IN_SET()` 返回第一个参数在第二个参数中出现的位置 @@ -528,7 +528,7 @@ SELECT FIND_IN_SET('Go', 'COBOL,BASIC,Rust,Go,Java,Fortran'); 1 row in set (0.00 sec) ``` -### [`FORMAT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_format) +### `FORMAT()` `FORMAT(X,D[,locale])` 函数用于将数字 `X` 格式化为类似于 `“#,###,###.##”` 的格式,四舍五入保留 `D` 位小数,并将结果作为字符串返回。 @@ -578,7 +578,7 @@ mysql> SELECT FORMAT(1234.56, 1, 'en_US'); +-----------------------------+ ``` -### [`FROM_BASE64()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_from-base64) +### `FROM_BASE64()` `FROM_BASE64(str)` 函数用于对 [Base64](https://datatracker.ietf.org/doc/html/rfc4648) 编码的字符串进行解码,并将解码结果以十六进制字符串的形式返回。 @@ -625,7 +625,7 @@ mysql> SELECT FROM_BASE64('MTIzNDU2'); +--------------------------------------------------+ ``` -### [`HEX()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_hex) +### `HEX()` `HEX()` 函数用于将输入的参数转换为其十六进制值的字符串表示形式。该参数可以为字符串或数字。 @@ -675,7 +675,7 @@ SELECT HEX(NULL); +-----------+ ``` -### [`INSERT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_insert) +### `INSERT()` `INSERT(str, pos, len, newstr)` 函数用于将字符串 `str` 中的一个子字符串(从位置 `pos` 开始,长度为 `len`)替换为字符串 `newstr`。该函数是多字节安全的。 @@ -730,7 +730,7 @@ SELECT INSERT('PingCAP 数据库', 1, 7, 'TiDB'); +-------------------------------------------+ ``` -### [`INSTR()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_instr) +### `INSTR()` `INSTR(str, substr)` 函数用于获取子字符串 `substr` 在字符串 `str` 中第一次出现的位置。`substr` 和 `str` 均可以为字符串或数字。该函数与 [`LOCATE(substr, str)`](#locate) 函数的两参数版本功能相同,但参数顺序相反。 @@ -789,11 +789,11 @@ SELECT INSTR(0123, "12"); +-------------------+ ``` -### [`LCASE()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_lcase) +### `LCASE()` `LCASE(str)`函数与 [`LOWER(str)`](#lower) 函数功能相同,都是返回输入参数的小写形式。 -### [`LEFT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_left) +### `LEFT()` `LEFT()` 函数用于返回字符串左侧指定数量的字符。 @@ -868,7 +868,7 @@ SELECT LEFT(NULL, 3); +------------------------------+ ``` -### [`LENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_length) +### `LENGTH()` `LENGTH()` 函数用于返回字符串的字节长度。`LENGTH()` 将单个多字节字符视为多个字节,而 `CHAR_LENGTH()` 将单个多字节字符视为单个字符。 @@ -908,7 +908,7 @@ SELECT LENGTH(NULL); +--------------+ ``` -### [`LIKE`](https://dev.mysql.com/doc/refman/8.0/en/string-comparison-functions.html#operator_like) +### `LIKE` `LIKE` 用于进行简单字符串匹配。表达式 `expr LIKE pat [ESCAPE 'escape_char']` 返回 `1` (`TRUE`) 或 `0` (`FALSE`)。如果 `expr` 或 `pat` 中任一个为 `NULL`,结果为 `NULL`。 @@ -1045,7 +1045,7 @@ SELECT '🍣🍺Sushi🍣🍺' COLLATE utf8mb4_unicode_ci LIKE '%SUSHI%' AS resu +--------+ ``` -### [`LOCATE()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_locate) +### `LOCATE()` `LOCATE(substr, str[, pos])` 函数用于返回子字符串 `substr` 在字符串 `str` 中第一次出现的位置。`pos` 参数是可选的,用于指定查找的起始位置。 @@ -1224,7 +1224,7 @@ SELECT LOCATE(_binary'B', 'aBcde'); +-----------------------------+ ``` -### [`LOWER()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_lower) +### `LOWER()` `LOWER(str)` 函数用于将输入的参数 `str` 中的所有字符转换为小写。该参数可以为字符串或数字。 @@ -1254,7 +1254,7 @@ SELECT LOWER(-012); +-------------+ ``` -### [`LPAD()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_lpad) +### `LPAD()` `LPAD(str, len, padstr)` 函数返回字符串参数,左侧填充指定字符串 `padstr`,直到字符串长度达到 `len` 个字符。 @@ -1294,7 +1294,7 @@ SELECT LPAD('TiDB',-2,'>'); 1 row in set (0.00 sec) ``` -### [`LTRIM()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_ltrim) +### `LTRIM()` `LTRIM()` 函数用于删除给定的字符串中的前导空格(即字符串开头的连续空格)。 @@ -1336,7 +1336,7 @@ SELECT CONCAT('«',LTRIM(' hello'),'»'); 1 row in set (0.00 sec) ``` -### [`MAKE_SET()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_make-set) +### `MAKE_SET()` `MAKE_SET()` 函数根据输入的 `bits` 参数中相应的 bit 是否为 `1` 返回一组由逗号分隔的字符串。 @@ -1426,7 +1426,7 @@ SELECT MAKE_SET(b'111','foo','bar','baz'); 1 row in set (0.0002 sec) ``` -### [`MID()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_mid) +### `MID()` `MID(str, pos[, len])` 函数返回从指定的 `pos` 位置开始的长度为 `len` 的子字符串。 @@ -1466,7 +1466,7 @@ SELECT MID('abcdef',2); 1 row in set (0.00 sec) ``` -### [`NOT LIKE`](https://dev.mysql.com/doc/refman/8.0/en/string-comparison-functions.html#operator_not-like) +### `NOT LIKE` 否定简单模式匹配。 @@ -1504,11 +1504,11 @@ SELECT 'aaa' LIKE 'b%', 'aaa' NOT LIKE 'b%'; 1 row in set (0.00 sec) ``` -### [`NOT REGEXP`](https://dev.mysql.com/doc/refman/8.0/en/regexp.html#operator_not-regexp) +### `NOT REGEXP` [`REGEXP`](#regexp) 的否定形式 -### [`OCT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_oct) +### `OCT()` `OCT()` 函数用于返回一个数值的[八进制](https://zh.wikipedia.org/wiki/八进制)表示,形式为字符串。 @@ -1554,11 +1554,11 @@ SELECT n, OCT(n) FROM nr; 20 rows in set (0.00 sec) ``` -### [`OCTET_LENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_octet-length) +### `OCTET_LENGTH()` 与 [`LENGTH()`](#length) 功能相同 -### [`ORD()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_ord) +### `ORD()` 返回给定的参数中最左侧字符的字符编码。 @@ -1611,11 +1611,11 @@ SELECT ORD('e'), ORD('ë'), HEX('e'), HEX('ë'); 1 row in set (0.00 sec) ``` -### [`POSITION()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_position) +### `POSITION()` 与 [`LOCATE()`](#locate) 功能相同 -### [`QUOTE()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_quote) +### `QUOTE()` `QUOTE()` 函数用于转义字符串,使其可以在 SQL 语句中使用。 @@ -1640,7 +1640,7 @@ SELECT QUOTE(0x002774657374); 1 row in set (0.00 sec) ``` -### [`REGEXP`](https://dev.mysql.com/doc/refman/8.0/en/regexp.html#operator_regexp) +### `REGEXP` 使用正则表达式匹配模式 @@ -1699,7 +1699,7 @@ WHERE 1 row in set (0.01 sec) ``` -### [`REGEXP_INSTR()`](https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-instr) +### `REGEXP_INSTR()` 返回满足正则的子字符串的第一个索引位置(与 MySQL 不完全兼容,具体请参考[正则函数与 MySQL 的兼容性](#正则函数与-mysql-的兼容性)) @@ -1838,7 +1838,7 @@ SELECT REGEXP_INSTR('abcabc','A' COLLATE utf8mb4_bin); 1 row in set (0.00 sec) ``` -### [`REGEXP_LIKE()`](https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-like) +### `REGEXP_LIKE()` 判断字符串是否满足正则表达式(与 MySQL 不完全兼容,具体请参考[正则函数与 MySQL 的兼容性](#正则函数与-mysql-的兼容性)) @@ -1891,7 +1891,7 @@ SELECT REGEXP_LIKE('abc','^A','i'); 1 row in set (0.00 sec) ``` -### [`REGEXP_REPLACE()`](https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-replace) +### `REGEXP_REPLACE()` 替换满足正则表达式的子字符串(与 MySQL 不完全兼容,具体请参考[正则函数与 MySQL 的兼容性](#正则函数与-mysql-的兼容性)) @@ -1985,7 +1985,7 @@ SELECT REGEXP_REPLACE('TooDB', 'O{2}','i',1,1,'i'); 1 row in set (0.00 sec) ``` -### [`REGEXP_SUBSTR()`](https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-substr) +### `REGEXP_SUBSTR()` 返回满足正则表达式的子字符串(与 MySQL 不完全兼容,具体请参考[正则函数与 MySQL 的兼容性](#正则函数与-mysql-的兼容性)) @@ -2006,7 +2006,7 @@ SELECT REGEXP_SUBSTR('This is TiDB','Ti.{2}'); 1 row in set (0.00 sec) ``` -### [`REPEAT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_repeat) +### `REPEAT()` `REPEAT()` 函数用于以指定次数重复一个字符串。 @@ -2066,47 +2066,47 @@ SELECT REPEAT('ha',3); 1 row in set (0.00 sec) ``` -### [`REPLACE()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_replace) +### `REPLACE()` 替换所有出现的指定字符串 -### [`REVERSE()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_reverse) +### `REVERSE()` 反转字符串里的所有字符 -### [`RIGHT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_right) +### `RIGHT()` 返回指定数量的最右侧的字符 -### [`RLIKE`](https://dev.mysql.com/doc/refman/8.0/en/regexp.html#operator_regexp) +### `RLIKE` 与 [`REGEXP`](#regexp) 功能相同 -### [`RPAD()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_rpad) +### `RPAD()` 以指定次数添加字符串 -### [`RTRIM()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_rtrim) +### `RTRIM()` 去掉后缀空格 -### [`SPACE()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_space) +### `SPACE()` 返回指定数量的空格,形式为字符串 -### [`STRCMP()`](https://dev.mysql.com/doc/refman/8.0/en/string-comparison-functions.html#function_strcmp) +### `STRCMP()` 比较两个字符串 -### [`SUBSTR()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_substr) +### `SUBSTR()` 返回指定的子字符串 -### [`SUBSTRING()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_substring) +### `SUBSTRING()` 返回指定的子字符串 -### [`SUBSTRING_INDEX()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_substring-index) +### `SUBSTRING_INDEX()` `SUBSTRING_INDEX()` 函数用于按照指定的分隔符和次数从字符串中提取子字符串。该函数在处理以特定分隔符分隔的数据时特别有用,例如解析 CSV 数据或处理日志文件。 @@ -2155,7 +2155,7 @@ SELECT SUBSTRING_INDEX('www.tidbcloud.com', '.', -1); +------------------------------------------+ ``` -### [`TO_BASE64()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_to-base64) +### `TO_BASE64()` `TO_BASE64()` 函数用于将输入的参数转换为 base-64 编码形式的字符串,并按照当前连接的字符集和排序规则返回结果。base-64 编码的字符串可以使用 [`FROM_BASE64()`](#from_base64) 函数进行解码。 @@ -2200,15 +2200,15 @@ SELECT TO_BASE64(6); +--------------+ ``` -### [`TRANSLATE()`](https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/TRANSLATE.html#GUID-80F85ACB-092C-4CC7-91F6-B3A585E3A690) +### `TRANSLATE()` 将字符串中出现的所有指定字符替换为其它字符。这个函数不会像 Oracle 一样将空字符串视为`NULL` -### [`TRIM()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_trim) +### `TRIM()` 去掉前缀和后缀空格 -### [`UCASE()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_ucase) +### `UCASE()` `UCASE()` 函数将字符串转换为大写字母,此函数等价于 `UPPER()` 函数。 @@ -2232,7 +2232,7 @@ SELECT UCASE('bigdata') AS result_upper, UCASE(null) AS result_null; +--------------+-------------+ ``` -### [`UNHEX()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_unhex) +### `UNHEX()` `UNHEX()` 函数执行 `HEX()` 函数的逆运算,将参数中的每对字符视为十六进制数字,并将其转换为该数字表示的字符,返回值为二进制字符串。 @@ -2257,7 +2257,7 @@ SELECT UNHEX('54694442'); +--------------------------------------+ ``` -### [`UPPER()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_upper) +### `UPPER()` `UPPER()` 函数将字符串转换为大写字母,此函数等价于 `UCASE()` 函数。 @@ -2281,7 +2281,7 @@ SELECT UPPER('bigdata') AS result_upper, UPPER(null) AS result_null; +--------------+-------------+ ``` -### [`WEIGHT_STRING()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_weight-string) +### `WEIGHT_STRING()` `WEIGHT_STRING()` 函数返回字符串的权重(二进制字符),主要用于多字符集场景下的排序和比较操作。如果参数为 `NULL`,则返回 `NULL`。语法示例如下: diff --git a/functions-and-operators/window-functions.md b/functions-and-operators/window-functions.md index 9a5d6783cec9..2e448e2aedcc 100644 --- a/functions-and-operators/window-functions.md +++ b/functions-and-operators/window-functions.md @@ -31,7 +31,7 @@ TiDB 支持除 `GROUP_CONCAT()` 和 `APPROX_PERCENTILE()` 以外的所有 [`GROU | [`RANK()`](#rank) | 返回分区中当前行的排名,排名可能不连续 | | [`ROW_NUMBER()`](#row_number) | 返回分区中当前行的编号 | -## [`CUME_DIST()`](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_cume-dist) +## `CUME_DIST()` `CUME_DIST()` 计算一个值在一组值中的累积分布。请注意,你需要在 `CUME_DIST()` 后使用 `ORDER BY` 子句对该组中的值进行排序。否则,此函数将不会返回预期值。 @@ -65,7 +65,7 @@ FROM 4 rows in set (0.00 sec) ``` -## [`DENSE_RANK()`](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_dense-rank) +## `DENSE_RANK()` `DENSE_RANK()` 函数返回当前行的排名。它的作用类似于 [`RANK()`](#rank),但在处理具有相同值和排序条件的行时能够确保排名是连续的。 @@ -101,7 +101,7 @@ FROM ( 6 rows in set (0.00 sec) ``` -## [`FIRST_VALUE()`](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_first-value) +## `FIRST_VALUE()` `FIRST_VALUE(expr)` 返回窗口中的第一个值。 @@ -140,7 +140,7 @@ ORDER BY 4 rows in set (0.00 sec) ``` -## [`LAG()`](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_lag) +## `LAG()` 函数 `LAG(expr [, num [, default]])` 返回当前行之前第 `num` 行的 `expr` 值。如果不存在该行,则返回 `default` 值。默认情况下,未指定时,`num` 为 `1`,`default` 为 `NULL`。 @@ -182,7 +182,7 @@ FROM 10 rows in set (0.01 sec) ``` -## [`LAST_VALUE()`](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_last-value) +## `LAST_VALUE()` `LAST_VALUE()` 函数返回窗口中的最后一个值。 @@ -225,7 +225,7 @@ ORDER BY 10 rows in set (0.00 sec) ``` -## [`LEAD()`](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_lead) +## `LEAD()` 函数 `LEAD(expr [, num [,default]])` 返回当前行之后第 `num` 行的 `expr` 值。如果不存在该行,则返回 `default` 值。默认情况下,未指定时,`num` 为 `1`,`default` 为 `NULL`。 @@ -268,7 +268,7 @@ FROM 10 rows in set (0.00 sec) ``` -## [`NTH_VALUE()`](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_nth-value) +## `NTH_VALUE()` 函数 `NTH_VALUE(expr, n)` 返回窗口的第 n 个值。 @@ -316,7 +316,7 @@ ORDER BY 10 rows in set (0.00 sec) ``` -## [`NTILE()`](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_ntile) +## `NTILE()` `NTILE(n)` 函数将窗口划分为 `n` 个分组,并返回各行的分组编号。 @@ -358,7 +358,7 @@ FROM 10 rows in set (0.00 sec) ``` -## [`PERCENT_RANK()`](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_percent-rank) +## `PERCENT_RANK()` `PERCENT_RANK()` 函数返回一个介于 0 和 1 之间的数字,表示值小于当前行值的行的百分比。 @@ -395,7 +395,7 @@ FROM ( 6 rows in set (0.00 sec) ``` -## [`RANK()`](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_rank) +## `RANK()` `RANK()` 函数的作用类似于 [`DENSE_RANK()`](#dense_rank),但在处理具有相同值和排序条件的行时返回的排名是不连续的。这意味着它提供的是绝对排名。例如,排名 7 意味着有 6 个行的排名更靠前。 @@ -432,7 +432,7 @@ FROM ( 6 rows in set (0.00 sec) ``` -## [`ROW_NUMBER()`](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_row-number) +## `ROW_NUMBER()` `ROW_NUMBER()` 返回结果集中当前行的行号。 From 6d29c4258764b29ff4e61dc29c368361e7f5154d Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 17 Nov 2025 18:59:16 +0800 Subject: [PATCH 4/4] Update functions-and-operators/json-functions/json-functions-aggregate.md --- .../json-functions/json-functions-aggregate.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/json-functions/json-functions-aggregate.md b/functions-and-operators/json-functions/json-functions-aggregate.md index 7c396cf4cf89..c564fa588517 100644 --- a/functions-and-operators/json-functions/json-functions-aggregate.md +++ b/functions-and-operators/json-functions/json-functions-aggregate.md @@ -7,7 +7,7 @@ summary: 了解聚合 JSON 值的 JSON 函数。 本文档介绍 TiDB [聚合函数](/functions-and-operators/aggregate-group-by-functions.md) 中专门用于处理 JSON 的聚合函数。 -TiDB 支持使用 MySQL 8.0 中提供的[两个 JSON 聚合函数](https://dev.mysql.com/doc/refman/8.0/en/json-aggregation-functions.html)。 +TiDB 支持使用 MySQL 8.0 中提供的[两个 JSON 聚合函数](https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html)。 ## `JSON_ARRAYAGG()`