From 69b2f2cbb8fb1f2a8e98dac7e0cd54599513e5c4 Mon Sep 17 00:00:00 2001 From: takaidohigasi Date: Wed, 10 Jan 2024 14:55:14 +0900 Subject: [PATCH] string-functions: add instrunctions for LEFT(), LENGTH() (#15491) --- functions-and-operators/string-functions.md | 91 +++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/functions-and-operators/string-functions.md b/functions-and-operators/string-functions.md index 78d027cd6e9c0..eeb31c06ee078 100644 --- a/functions-and-operators/string-functions.md +++ b/functions-and-operators/string-functions.md @@ -173,10 +173,101 @@ Synonym for `LOWER()`. Return the leftmost number of characters as specified. +* LEFT(`str`, `len`) + * 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. +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.