From 73778c0a66e995360609164eb90194546ddb20fa Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Tue, 6 Feb 2024 17:31:04 +0800 Subject: [PATCH 1/6] 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 bde9afac08afa1e46f8c5454323aa61cb6ecf9e5 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Tue, 6 Feb 2024 17:31:08 +0800 Subject: [PATCH 2/6] 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 5bd2d8c61305209abee80b395da08181ebe6e3cc Mon Sep 17 00:00:00 2001 From: qiancai Date: Tue, 6 Feb 2024 18:23:48 +0800 Subject: [PATCH 3/6] Update string-functions.md --- functions-and-operators/string-functions.md | 86 ++++++++++++++++++++- 1 file changed, 82 insertions(+), 4 deletions(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 7018c7a0dbf6..18946fd6f97b 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -493,13 +493,65 @@ mysql> SELECT FROM_BASE64('MTIzNDU2'); 在指定位置插入一个子字符串,最多不超过指定字符数 -### [`INSTR()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_instr) +`INSTR(str, substr)` 函数用于获取子字符串 `substr` 在字符串 `str` 中第一次出现的位置。`substr` 和 `str` 均可以为字符串或数字。该函数与 [`LOCATE(substr, str)`](#locate) 函数的两参数版本功能相同,但参数顺序相反。 -返回第一次出现的子字符串的索引 +> **注意:** +> +> `INSTR(str, substr)` 函数是否区分大小取决于 TiDB 所使用的[排序规则](/character-set-and-collation.md)。二进制排序规则(以 `_bin` 为后缀)区分大小写,而通用排序规则(以 `_general_ci` 或 `_ai_ci` 为后缀)不区分大小写。 + +- 如果任一输入参数为数字,该函数将数字视为字符串处理。 +- 如果 `substr` 不在 `str` 中,函数返回 `0`。否则,返回 `substr` 在 `str` 中第一次出现的位置。 +- 如果任一参数为 `NULL`,该函数返回 `NULL`。 + +示例: + +```sql +SELECT INSTR("pingcap.com", "tidb"); ++------------------------------+ +| INSTR("pingcap.com", "tidb") | ++------------------------------+ +| 0 | ++------------------------------+ +``` + +```sql +SELECT INSTR("pingcap.com/tidb", "tidb"); ++-----------------------------------+ +| INSTR("pingcap.com/tidb", "tidb") | ++-----------------------------------+ +| 13 | ++-----------------------------------+ +``` + +```sql +SELECT INSTR("pingcap.com/tidb" COLLATE utf8mb4_bin, "TiDB"); ++-------------------------------------------------------+ +| INSTR("pingcap.com/tidb" COLLATE utf8mb4_bin, "TiDB") | ++-------------------------------------------------------+ +| 0 | ++-------------------------------------------------------+ +``` + +```sql +SELECT INSTR("pingcap.com/tidb" COLLATE utf8mb4_general_ci, "TiDB"); ++--------------------------------------------------------------+ +| INSTR("pingcap.com/tidb" COLLATE utf8mb4_general_ci, "TiDB") | ++--------------------------------------------------------------+ +| 13 | ++--------------------------------------------------------------+ +``` + +```sql +SELECT INSTR(0123, "12"); ++-------------------+ +| INSTR(0123, "12") | ++-------------------+ +| 1 | ++-------------------+ ### [`LCASE()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_lcase) -与 `LOWER()` 功能相同 +`LCASE(str)`函数与 [`LOWER(str)`](#lower) 函数功能相同,都是返回输入参数的小写形式。 ### [`LEFT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_left) @@ -519,7 +571,33 @@ mysql> SELECT FROM_BASE64('MTIzNDU2'); ### [`LOWER()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_lower) -返回全小写的参数 +`LOWER(str)` 函数用于将输入的参数 `str` 中的所有字符转换为小写。该参数可以为字符串或数字。 + +- 如果输入参数为字符串,该函数返回字符串的小写形式。 +- 如果输入参数为数字,该函数将会去掉该数字中的前导零。 +- 如果输入参数为 `NULL`,该函数返回 `NULL`。 + +示例: + +```sql +SELECT LOWER("TiDB"); + ++---------------+ +| LOWER("TiDB") | ++---------------+ +| tidb | ++---------------+ +``` + +```sql +SELECT LOWER(-012); + ++-------------+ +| LOWER(-012) | ++-------------+ +| -12 | ++-------------+ +``` ### [`LPAD()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_lpad) From 13b15240bbb954317bb3f154ecd1037fbe85a179 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Tue, 6 Feb 2024 18:24:48 +0800 Subject: [PATCH 4/6] Update functions-and-operators/string-functions.md --- functions-and-operators/string-functions.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 18946fd6f97b..57c34ffaec3e 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -493,6 +493,8 @@ mysql> SELECT FROM_BASE64('MTIzNDU2'); 在指定位置插入一个子字符串,最多不超过指定字符数 +### [`INSTR()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_instr) + `INSTR(str, substr)` 函数用于获取子字符串 `substr` 在字符串 `str` 中第一次出现的位置。`substr` 和 `str` 均可以为字符串或数字。该函数与 [`LOCATE(substr, str)`](#locate) 函数的两参数版本功能相同,但参数顺序相反。 > **注意:** From 6c1fee86e9a32a24d7c82004b911f4db34777e6d Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Wed, 7 Feb 2024 16:34:25 +0800 Subject: [PATCH 5/6] Apply suggestions from code review --- functions-and-operators/string-functions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 57c34ffaec3e..d7e7b7199481 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -497,7 +497,7 @@ mysql> SELECT FROM_BASE64('MTIzNDU2'); `INSTR(str, substr)` 函数用于获取子字符串 `substr` 在字符串 `str` 中第一次出现的位置。`substr` 和 `str` 均可以为字符串或数字。该函数与 [`LOCATE(substr, str)`](#locate) 函数的两参数版本功能相同,但参数顺序相反。 -> **注意:** +> **注意:** > > `INSTR(str, substr)` 函数是否区分大小取决于 TiDB 所使用的[排序规则](/character-set-and-collation.md)。二进制排序规则(以 `_bin` 为后缀)区分大小写,而通用排序规则(以 `_general_ci` 或 `_ai_ci` 为后缀)不区分大小写。 @@ -505,7 +505,7 @@ mysql> SELECT FROM_BASE64('MTIzNDU2'); - 如果 `substr` 不在 `str` 中,函数返回 `0`。否则,返回 `substr` 在 `str` 中第一次出现的位置。 - 如果任一参数为 `NULL`,该函数返回 `NULL`。 -示例: +示例: ```sql SELECT INSTR("pingcap.com", "tidb"); From 867386df719540e89ca93aac4a6ed58da968d636 Mon Sep 17 00:00:00 2001 From: qiancai Date: Wed, 7 Feb 2024 16:42:13 +0800 Subject: [PATCH 6/6] Update string-functions.md --- functions-and-operators/string-functions.md | 1 + 1 file changed, 1 insertion(+) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 6308813030d6..f94468f5660e 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -577,6 +577,7 @@ SELECT INSTR(0123, "12"); +-------------------+ | 1 | +-------------------+ +``` ### [`LCASE()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_lcase)