From dc177e2e5a32b54593530376c0d2ff7135bd5d73 Mon Sep 17 00:00:00 2001 From: takaidohigasi Date: Wed, 10 Jan 2024 14:55:14 +0900 Subject: [PATCH 01/12] string-functions: add instrunctions for LEFT() and LENGTH() --- functions-and-operators/string-functions.md | 95 +++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 78d027cd6e9c0..978d76e11c3da 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -173,10 +173,105 @@ Synonym for `LOWER()`. Return the leftmost number of characters as specified. +* usage: LEFT(`str`, `len`) + * len: length of character to return + * str: original string to extract characters +* if `len` is equal or less than 0, the function returns empty string +* function is multibyte safe. +* If any argument is `NULL`, the function returns `NULL`. + +Examples: + +```sql +SELECT LEFT('ABCED', 3); ++------------------+ +| LEFT('ABCED', 3) | ++------------------+ +| ABC | ++------------------+ + +SELECT LEFT('ABCED', 6); ++------------------+ +| LEFT('ABCED', 6) | ++------------------+ +| ABCED | ++------------------+ +``` + +```sql +SELECT LEFT('ABCED', 0); ++------------------+ +| LEFT('ABCED', 0) | ++------------------+ +| | ++------------------+ + +SELECT LEFT('ABCED', -1); ++-------------------+ +| LEFT('ABCED', -1) | ++-------------------+ +| | ++-------------------+ +``` + +```sql +SELECT LEFT('šŸ£ABC', 3); ++--------------------+ +| LEFT('šŸ£ABC', 3) | ++--------------------+ +| šŸ£AB | ++--------------------+ +``` + +```sql +SELECT LEFT('ABC', NULL); ++-------------------+ +| LEFT('ABC', NULL) | ++-------------------+ +| NULL | ++-------------------+ + +SELECT LEFT(NULL, 3); ++------------------------------+ +| LEFT(NULL, 3) | ++------------------------------+ +| NULL | ++------------------------------+ +``` + ### [`LENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_length) Return the length of a string in bytes. +* If any argument is `NULL`, the function returns `NULL`. + +Examples: + +```sql +SELECT LENGTH('ABC'); ++---------------+ +| LENGTH('ABC') | ++---------------+ +| 3 | ++---------------+ + +SELECT LENGTH('šŸ£ABC'); ++-------------------+ +| LENGTH('šŸ£ABC') | ++-------------------+ +| 7 | ++-------------------+ +``` + +```sql +SELECT LENGTH(NULL); ++--------------+ +| LENGTH(NULL) | ++--------------+ +| NULL | ++--------------+ +``` + ### [`LIKE`](https://dev.mysql.com/doc/refman/8.0/en/string-comparison-functions.html#operator_like) Simple pattern matching. From a6f6f4e7e4f5704d694ef5b931bc21fd35585f26 Mon Sep 17 00:00:00 2001 From: takaidohigasi Date: Wed, 10 Jan 2024 16:20:37 +0900 Subject: [PATCH 02/12] add note and an example for CHAR_LENGTH for LENGTH() function document --- functions-and-operators/string-functions.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 978d76e11c3da..f89ec86d094a0 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -242,6 +242,7 @@ SELECT LEFT(NULL, 3); ### [`LENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_length) Return the length of a string in bytes. +`LENGTH()` count a multibyte character as multi bytes while `CHAR_LENGTH()` count it as a single code point * If any argument is `NULL`, the function returns `NULL`. @@ -261,6 +262,13 @@ SELECT LENGTH('šŸ£ABC'); +-------------------+ | 7 | +-------------------+ + +SELECT CHAR_LENGTH('šŸ£ABC'); ++------------------------+ +| CHAR_LENGTH('šŸ£ABC') | ++------------------------+ +| 4 | ++------------------------+ ``` ```sql From d0305e4b0fb67dc3cc942953bc691fd31b18ea27 Mon Sep 17 00:00:00 2001 From: takaidohigasi Date: Wed, 10 Jan 2024 16:41:40 +0900 Subject: [PATCH 03/12] fix not to use manual line break MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: DaniĆ«l van Eeden --- 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 f89ec86d094a0..a0bbf45add4fc 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -242,6 +242,7 @@ SELECT LEFT(NULL, 3); ### [`LENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_length) Return the length of a string in bytes. + `LENGTH()` count a multibyte character as multi bytes while `CHAR_LENGTH()` count it as a single code point * If any argument is `NULL`, the function returns `NULL`. From 1544808b5f586d33b69971a4e8b161e152943059 Mon Sep 17 00:00:00 2001 From: takaidohigasi Date: Mon, 15 Jan 2024 10:07:04 +0900 Subject: [PATCH 04/12] add explanation for LEFT() when len is greater than string length Co-authored-by: SeaRise --- 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 a0bbf45add4fc..e10fd07858fa5 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -179,6 +179,7 @@ Return the leftmost number of characters as specified. * if `len` is equal or less than 0, the function returns empty string * function is multibyte safe. * If any argument is `NULL`, the function returns `NULL`. +* If `len` is greater than the length of `str`, the function returns `str`. Examples: From 3952115c107cd828fad54a05a1a05c06c18b9e58 Mon Sep 17 00:00:00 2001 From: takaidohigasi Date: Mon, 15 Jan 2024 10:08:47 +0900 Subject: [PATCH 05/12] Update string-functions.md --- 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 e10fd07858fa5..49e5e1617acb7 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -176,10 +176,10 @@ Return the leftmost number of characters as specified. * usage: LEFT(`str`, `len`) * len: length of character to return * str: original string to extract characters -* if `len` is equal or less than 0, the function returns empty string +* if `len` is equal or less than 0, the function returns empty string. +* If `len` is greater than the length of `str`, the function returns the length of `str`. * function is multibyte safe. * If any argument is `NULL`, the function returns `NULL`. -* If `len` is greater than the length of `str`, the function returns `str`. Examples: From 9f7c6e399504ff2e639e5e70639ac6fb7c639471 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 29 Jan 2024 12:06:22 +0800 Subject: [PATCH 06/12] refine the descriptions --- functions-and-operators/string-functions.md | 25 +++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 49e5e1617acb7..464d676c6b86f 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -173,13 +173,20 @@ Synonym for `LOWER()`. Return the leftmost number of characters as specified. -* usage: LEFT(`str`, `len`) - * len: length of character to return - * str: original string to extract characters -* if `len` is equal or less than 0, the function returns empty string. -* If `len` is greater than the length of `str`, the function returns the length of `str`. -* function is multibyte safe. -* If any argument is `NULL`, the function returns `NULL`. + +Syntax: + +```sql +LEFT(`str`, `len`) +``` + +- `str`: the original string to extract characters. +- `len`: the length of characters to be returned. + +- If `len` is equal to or less than 0, the function returns an empty string. +- If `len` is greater than the length of `str`, the function returns the length of `str`. +- If `str` contains a multibyte character, the function counts it as a single code point. +- If any argument is `NULL`, the function returns `NULL`. Examples: @@ -244,9 +251,9 @@ SELECT LEFT(NULL, 3); Return the length of a string in bytes. -`LENGTH()` count a multibyte character as multi bytes while `CHAR_LENGTH()` count it as a single code point +`LENGTH()` counts a multibyte character as multi bytes while `CHAR_LENGTH()` counts a multibyte character as a single code point. -* If any argument is `NULL`, the function returns `NULL`. +If the argument is `NULL`, the function returns `NULL`. Examples: From 7daa9edb32bc079e3a43ecd6d5c399ac61ec724f Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 29 Jan 2024 12:08:30 +0800 Subject: [PATCH 07/12] refine the descriptions --- functions-and-operators/string-functions.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 464d676c6b86f..7cc8680298106 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -180,12 +180,10 @@ Syntax: LEFT(`str`, `len`) ``` -- `str`: the original string to extract characters. +- `str`: the original string to extract characters. If `str` contains a multibyte character, the function counts it as a single code point. - `len`: the length of characters to be returned. - -- If `len` is equal to or less than 0, the function returns an empty string. -- If `len` is greater than the length of `str`, the function returns the length of `str`. -- If `str` contains a multibyte character, the function counts it as a single code point. + - If `len` is equal to or less than 0, the function returns an empty string. + - If `len` is greater than the length of `str`, the function returns the length of `str`. - If any argument is `NULL`, the function returns `NULL`. Examples: From 30494d3baa69b4f8f759c6e6c747b1ea578a4e4a Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 29 Jan 2024 13:57:37 +0800 Subject: [PATCH 08/12] refine the descriptions --- 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 7cc8680298106..2ad1f4fa6d6a3 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -171,7 +171,7 @@ Synonym for `LOWER()`. ### [`LEFT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_left) -Return the leftmost number of characters as specified. +The `LEFT()` function returns a specified number of characters from the left side of a string. Syntax: @@ -247,7 +247,7 @@ SELECT LEFT(NULL, 3); ### [`LENGTH()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_length) -Return the length of a string in bytes. +The `LENGTH()` function returns the length of a string in bytes. `LENGTH()` counts a multibyte character as multi bytes while `CHAR_LENGTH()` counts a multibyte character as a single code point. From da84cb4e249f34eb263ca47cf8c6109d28ebb357 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 29 Jan 2024 14:02:42 +0800 Subject: [PATCH 09/12] Update functions-and-operators/string-functions.md --- functions-and-operators/string-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 2ad1f4fa6d6a3..2e38409465ba9 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -183,7 +183,7 @@ LEFT(`str`, `len`) - `str`: the original string to extract characters. If `str` contains a multibyte character, the function counts it as a single code point. - `len`: the length of characters to be returned. - If `len` is equal to or less than 0, the function returns an empty string. - - If `len` is greater than the length of `str`, the function returns the length of `str`. + - If `len` is greater than the length of `str`, the function returns the original `str`. - If any argument is `NULL`, the function returns `NULL`. Examples: From 9bfb3ca767e8bf2ce8da2ce91392c2076b50e321 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 29 Jan 2024 14:07:01 +0800 Subject: [PATCH 10/12] remove an empty line --- functions-and-operators/string-functions.md | 1 - 1 file changed, 1 deletion(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 2e38409465ba9..535ece1bbb20a 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -173,7 +173,6 @@ Synonym for `LOWER()`. The `LEFT()` function returns a specified number of characters from the left side of a string. - Syntax: ```sql From a764504a9236493e059c618da3fc9db50c6f41ed Mon Sep 17 00:00:00 2001 From: takaidohigasi Date: Mon, 29 Jan 2024 16:59:45 +0900 Subject: [PATCH 11/12] Update functions-and-operators/string-functions.md Co-authored-by: xixirangrang --- functions-and-operators/string-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 535ece1bbb20a..9efc0ebd360f8 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -248,7 +248,7 @@ SELECT LEFT(NULL, 3); The `LENGTH()` function returns the length of a string in bytes. -`LENGTH()` counts a multibyte character as multi bytes while `CHAR_LENGTH()` counts a multibyte character as a single code point. +`LENGTH()` counts a multibyte character as multiple bytes while `CHAR_LENGTH()` counts a multibyte character as a single code point. If the argument is `NULL`, the function returns `NULL`. From 8b47e607f0dc54a2bc2826a7b854ef4148aa229b Mon Sep 17 00:00:00 2001 From: takaidohigasi Date: Mon, 29 Jan 2024 17:00:11 +0900 Subject: [PATCH 12/12] Update functions-and-operators/string-functions.md Co-authored-by: xixirangrang --- functions-and-operators/string-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 9efc0ebd360f8..dde6e298a80e1 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -182,7 +182,7 @@ LEFT(`str`, `len`) - `str`: the original string to extract characters. If `str` contains a multibyte character, the function counts it as a single code point. - `len`: the length of characters to be returned. - If `len` is equal to or less than 0, the function returns an empty string. - - If `len` is greater than the length of `str`, the function returns the original `str`. + - If `len` is equal to or greater than the length of `str`, the function returns the original `str`. - If any argument is `NULL`, the function returns `NULL`. Examples: