You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2025/10/25 02:47:19 UTC
(doris-website) branch master updated: [fix](doc] Fix the string function documention (#3005)
This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push:
new a8e346032aa [fix](doc] Fix the string function documention (#3005)
a8e346032aa is described below
commit a8e346032aa8040f633e0c5d0f7fe2805fce4d2e
Author: dwdwqfwe <14...@users.noreply.github.com>
AuthorDate: Sat Oct 25 10:47:13 2025 +0800
[fix](doc] Fix the string function documention (#3005)
## Versions
- [ ] dev
- [ ] 3.x
- [ ] 2.1
- [ ] 2.0
## Languages
- [ ] Chinese
- [ ] English
## Docs Checklist
- [ ] Checked by AI
- [ ] Test Cases Built
---
.../append-trailing-char-if-absent.md | 88 ++++++--
.../scalar-functions/string-functions/ascii.md | 126 ++++++++++--
.../string-functions/auto-partition-name.md | 144 +++++++------
.../string-functions/char-length.md | 73 +++++--
.../scalar-functions/string-functions/char.md | 84 +++++---
.../scalar-functions/string-functions/compress.md | 64 ++++--
.../scalar-functions/string-functions/concat-ws.md | 224 ++++++++++-----------
.../scalar-functions/string-functions/concat.md | 128 ++++++++++--
.../string-functions/count_substrings.md | 27 ++-
.../string-functions/digital-masking.md | 75 ++++++-
.../scalar-functions/string-functions/elt.md | 128 ++++++++++--
.../scalar-functions/string-functions/ends-with.md | 144 +++++++++++--
.../string-functions/find-in-set.md | 150 ++++++++++++--
.../string-functions/format-number.md | 78 ++++---
.../scalar-functions/string-functions/format.md | 82 +++++---
.../string-functions/from-base64.md | 91 +++++++--
.../scalar-functions/string-functions/hex.md | 78 +++++--
.../scalar-functions/string-functions/initcap.md | 67 +++++-
.../scalar-functions/string-functions/instr.md | 71 +++++--
.../string-functions/int-to-uuid.md | 26 ++-
.../scalar-functions/string-functions/lcase.md | 58 ++++--
.../scalar-functions/string-functions/length.md | 64 ++++--
.../scalar-functions/string-functions/locate.md | 62 ++++--
.../scalar-functions/string-functions/lpad.md | 76 ++++---
.../scalar-functions/string-functions/ltrim.md | 60 ++++--
.../scalar-functions/string-functions/make-set.md | 144 +++++++------
.../string-functions/mask-first-n.md | 142 ++++++++++---
.../string-functions/mask-last-n.md | 142 ++++++++++---
.../scalar-functions/string-functions/mask.md | 130 +++++++++---
.../string-functions/multi-search-all-positions.md | 95 +++++++--
.../string-functions/ngram-search.md | 72 +++++--
.../scalar-functions/string-functions/overlay.md | 69 +++----
.../string-functions/parse-data-size.md | 123 +++++++----
.../scalar-functions/string-functions/position.md | 158 +++++++++++++++
.../scalar-functions/string-functions/quote.md | 106 ++++++++--
.../string-functions/random_bytes.md | 73 +++++--
.../scalar-functions/string-functions/repeat.md | 155 ++++++++++++++
.../string-functions/replace-empty.md | 8 +-
.../scalar-functions/string-functions/replace.md | 86 ++++++--
.../scalar-functions/string-functions/reverse.md | 150 ++++++++++++++
.../scalar-functions/string-functions/rpad.md | 153 +++++++++++---
.../scalar-functions/string-functions/rtrim-in.md | 62 +++++-
.../scalar-functions/string-functions/rtrim.md | 103 ++++++++--
.../scalar-functions/string-functions/soundex.md | 161 ++++++++++-----
.../scalar-functions/string-functions/space.md | 44 +++-
.../string-functions/split-by-regexp.md | 142 +++++++++++--
.../string-functions/split-by-string.md | 139 +++++++++++--
.../string-functions/split-part.md | 110 +++++++++-
.../string-functions/starts-with.md | 148 ++++++++++++--
.../scalar-functions/string-functions/strcmp.md | 12 +-
.../scalar-functions/string-functions/strleft.md | 110 +++++++---
.../scalar-functions/string-functions/strright.md | 122 ++++++++---
.../string-functions/sub-replace.md | 88 ++++++--
.../string-functions/substring-index.md | 145 +++++++++----
.../scalar-functions/string-functions/substring.md | 30 ++-
.../scalar-functions/string-functions/to-base64.md | 132 ++++++++++--
.../scalar-functions/string-functions/translate.md | 86 ++++++--
.../scalar-functions/string-functions/trim-in.md | 106 +++++++---
.../scalar-functions/string-functions/trim.md | 120 ++++++++---
.../scalar-functions/string-functions/ucase.md | 125 ++++++++++--
.../string-functions/uncompress.md | 22 +-
.../scalar-functions/string-functions/unhex.md | 76 +++++--
.../string-functions/uuid-to-int.md | 113 +++++++++++
.../scalar-functions/string-functions/uuid.md | 38 +++-
.../string-functions/xpath-string.md | 16 +-
.../append-trailing-char-if-absent.md | 86 ++++++--
.../scalar-functions/string-functions/ascii.md | 120 ++++++++++-
.../string-functions/auto-partition-name.md | 144 +++++++------
.../string-functions/char-length.md | 69 +++++--
.../scalar-functions/string-functions/char.md | 73 +++++--
.../scalar-functions/string-functions/compress.md | 62 ++++--
.../scalar-functions/string-functions/concat-ws.md | 219 ++++++++++----------
.../scalar-functions/string-functions/concat.md | 121 +++++++++--
.../string-functions/count_substrings.md | 28 +--
.../string-functions/digital-masking.md | 79 ++++++--
.../scalar-functions/string-functions/elt.md | 130 ++++++++++--
.../scalar-functions/string-functions/ends-with.md | 140 +++++++++++--
.../string-functions/find-in-set.md | 147 ++++++++++++--
.../string-functions/format-number.md | 72 ++++---
.../scalar-functions/string-functions/format.md | 78 ++++---
.../string-functions/from-base64.md | 145 +++++++++++--
.../scalar-functions/string-functions/hex.md | 123 +++++++++--
.../scalar-functions/string-functions/initcap.md | 137 ++++++++++++-
.../scalar-functions/string-functions/instr.md | 141 +++++++++++--
.../string-functions/int-to-uuid.md | 14 ++
.../scalar-functions/string-functions/lcase.md | 99 +++++++--
.../scalar-functions/string-functions/length.md | 132 ++++++++++--
.../scalar-functions/string-functions/locate.md | 142 ++++++++++++-
.../scalar-functions/string-functions/lpad.md | 142 +++++++++++--
.../scalar-functions/string-functions/ltrim.md | 144 +++++++++++--
.../scalar-functions/string-functions/make-set.md | 141 +++++++------
.../string-functions/mask-first-n.md | 155 ++++++++++++--
.../string-functions/mask-last-n.md | 155 ++++++++++++--
.../scalar-functions/string-functions/mask.md | 143 +++++++++++--
.../string-functions/multi-search-all-positions.md | 91 +++++++--
.../string-functions/ngram-search.md | 76 +++++--
.../scalar-functions/string-functions/overlay.md | 71 +++----
.../string-functions/parse-data-size.md | 118 ++++++++---
.../scalar-functions/string-functions/position.md | 151 ++++++++++++--
.../scalar-functions/string-functions/quote.md | 102 ++++++++--
.../string-functions/random_bytes.md | 75 +++++--
.../scalar-functions/string-functions/repeat.md | 130 ++++++++++--
.../string-functions/replace-empty.md | 95 +++++----
.../scalar-functions/string-functions/replace.md | 132 +++++++++++-
.../scalar-functions/string-functions/reverse.md | 124 +++++++++++-
.../scalar-functions/string-functions/rpad.md | 150 +++++++++++---
.../scalar-functions/string-functions/rtrim-in.md | 55 ++++-
.../scalar-functions/string-functions/rtrim.md | 145 +++++++++++--
.../scalar-functions/string-functions/soundex.md | 156 +++++++++-----
.../scalar-functions/string-functions/space.md | 59 ++++--
.../string-functions/split-by-regexp.md | 136 +++++++++++--
.../string-functions/split-by-string.md | 133 ++++++++++--
.../string-functions/split-part.md | 133 ++++++++++--
.../string-functions/starts-with.md | 143 +++++++++++--
.../scalar-functions/string-functions/strleft.md | 133 +++++++++---
.../scalar-functions/string-functions/strright.md | 134 +++++++++---
.../string-functions/sub-replace.md | 111 ++++++++--
.../string-functions/substring-index.md | 139 +++++++++----
.../scalar-functions/string-functions/substring.md | 46 ++++-
.../scalar-functions/string-functions/to-base64.md | 122 +++++++++--
.../scalar-functions/string-functions/translate.md | 136 +++++++++----
.../scalar-functions/string-functions/trim-in.md | 104 +++++++---
.../scalar-functions/string-functions/trim.md | 114 ++++++++---
.../scalar-functions/string-functions/ucase.md | 121 +++++++++--
.../scalar-functions/string-functions/unhex.md | 137 ++++++++++---
.../string-functions/uuid-to-int.md | 88 +++++++-
.../scalar-functions/string-functions/uuid.md | 31 ++-
.../string-functions/xpath-string.md | 87 ++++++--
128 files changed, 10873 insertions(+), 2610 deletions(-)
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/append-trailing-char-if-absent.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/append-trailing-char-if-absent.md
index f6c4aed1657..b2b531e5d21 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/append-trailing-char-if-absent.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/append-trailing-char-if-absent.md
@@ -7,35 +7,89 @@
## Description
-Used to add a specific character (such as a space, a specific symbol, etc.) to the end of a string if the character does not exist at the end of the string. The function is to ensure that the string ends with a specific character.
+The APPEND_TRAILING_CHAR_IF_ABSENT function ensures that a string ends with a specified character. If the character does not exist at the end of the string, it is added; if it already exists, the string remains unchanged.
## Syntax
```sql
-APPEND_TRAILING_CHAR_IF_ABSENT ( <str> , <trailing_char> )
+APPEND_TRAILING_CHAR_IF_ABSENT(<str>, <trailing_char>)
```
## Parameters
-| Parameters | Description |
-|-------------------|-----------------------------|
-| `<str>` | Target string to be judged |
-| `<trailing_char>` | Character to be added to the end of the string (if the character does not exist) |
+| Parameter | Description |
+| ------------------ | ----------------------------------------- |
+| `<str>` | The target string to process. Type: VARCHAR |
+| `<trailing_char>` | The character that must appear at the end of the string. Type: VARCHAR |
-## Return value
+## Return Value
-Parameters The string after concatenation of `<str>` and `<trailing_char>` (if `<trailing_char>` does not exist in `<str>`)
+Returns VARCHAR type:
+- If `<trailing_char>` does not exist at the end of `<str>`, returns the concatenation of `<str>` and `<trailing_char>`
+- If `<trailing_char>` already exists at the end of `<str>`, returns the original `<str>`
-## Example
+Special cases:
+- If any argument is NULL, returns NULL
+- If `<str>` is an empty string, returns `<trailing_char>`
-``` sql
-SELECT APPEND_TRAILING_CHAR_IF_ABSENT('a','c'),APPEND_TRAILING_CHAR_IF_ABSENT('ac', 'c'),APPEND_TRAILING_CHAR_IF_ABSENT('ac', 'cd')
+## Examples
+
+1. Basic usage: Add character when it doesn't exist
+```sql
+SELECT APPEND_TRAILING_CHAR_IF_ABSENT('a', 'c');
+```
+```text
++------------------------------------------+
+| append_trailing_char_if_absent('a', 'c') |
++------------------------------------------+
+| ac |
++------------------------------------------+
```
-```text
-+------------------------------------------+-------------------------------------------+--------------------------------------------+
-| append_trailing_char_if_absent('a', 'c') | append_trailing_char_if_absent('ac', 'c') | append_trailing_char_if_absent('ac', 'cd') |
-+------------------------------------------+-------------------------------------------+--------------------------------------------+
-| ac | ac | accd |
-+------------------------------------------+-------------------------------------------+--------------------------------------------+
+2. Character already exists, don't add
+```sql
+SELECT APPEND_TRAILING_CHAR_IF_ABSENT('ac', 'c');
+```
+```text
++-------------------------------------------+
+| append_trailing_char_if_absent('ac', 'c') |
++-------------------------------------------+
+| ac |
++-------------------------------------------+
+```
+
+3. Empty string handling
+```sql
+SELECT APPEND_TRAILING_CHAR_IF_ABSENT('', '/');
+```
+```text
++------------------------------------------+
+| append_trailing_char_if_absent('', '/') |
++------------------------------------------+
+| / |
++------------------------------------------+
+```
+
+4. NULL value handling
+```sql
+SELECT APPEND_TRAILING_CHAR_IF_ABSENT(NULL, 'c');
+```
+```text
++-------------------------------------------+
+| append_trailing_char_if_absent(NULL, 'c') |
++-------------------------------------------+
+| NULL |
++-------------------------------------------+
+```
+
+5. UTF-8 character
+```sql
+SELECT APPEND_TRAILING_CHAR_IF_ABSENT('acf', 'ṛ');
+```
+```text
++----------------------------------------------+
+| APPEND_TRAILING_CHAR_IF_ABSENT('acf', 'ṛ') |
++----------------------------------------------+
+| acfṛ |
++----------------------------------------------+
```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/ascii.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/ascii.md
index 315b46edbd6..f3099a1d217 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/ascii.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/ascii.md
@@ -7,34 +7,136 @@
## Description
-Returns the ASCII code of the first character of a string
+Returns the ASCII code value of the first character in a string. This function only processes the first character of the string, returning only the ASCII value of the first character for multi-character strings.
## Syntax
```sql
-ASCII ( <str> )
+ASCII(<str>)
```
## Parameters
-| Parameter | Description |
-|-----------|-------------------------|
-| `<str>` | The string whose ASCII code of the first character needs to be calculated |
+| Parameter | Description |
+|---------|-----------------------------|
+| `<str>` | The string to get the ASCII code of the first character. Type: VARCHAR |
-## Return value
+## Return Value
-Parameter <str> ASCII code of the first character
+Returns INT type, representing the ASCII code value of the first character in the string.
-## Example
+Special cases:
+- If the parameter is NULL, returns NULL
+- If the string is empty, returns 0
+- If the first character is not an ASCII character (code value greater than 127), returns the corresponding byte value
+- For multi-byte UTF-8 characters, returns the value of the first byte
+## Examples
+
+1. Basic numeric characters
```sql
-SELECT ASCII('1'),ASCII('234')
+SELECT ASCII('1'), ASCII('234');
```
-
```text
+------------+--------------+
-| ascii('1') | ascii('234') |
+| ASCII('1') | ASCII('234') |
+------------+--------------+
| 49 | 50 |
+------------+--------------+
-```
\ No newline at end of file
+```
+
+2. Letter characters
+```sql
+SELECT ASCII('A'), ASCII('a'), ASCII('Z');
+```
+```text
++------------+------------+------------+
+| ASCII('A') | ASCII('a') | ASCII('Z') |
++------------+------------+------------+
+| 65 | 97 | 90 |
++------------+------------+------------+
+```
+
+3. Empty string handling
+```sql
+SELECT ASCII('');
+```
+```text
++-----------+
+| ASCII('') |
++-----------+
+| 0 |
++-----------+
+```
+
+4. NULL value handling
+```sql
+SELECT ASCII(NULL);
+```
+```text
++-------------+
+| ASCII(NULL) |
++-------------+
+| NULL |
++-------------+
+```
+
+5. Special symbols
+```sql
+SELECT ASCII(' '), ASCII('!'), ASCII('@');
+```
+```text
++------------+------------+------------+
+| ASCII(' ') | ASCII('!') | ASCII('@') |
++------------+------------+------------+
+| 32 | 33 | 64 |
++------------+------------+------------+
+```
+
+6. Control characters
+```sql
+SELECT ASCII('\t'), ASCII('\n'), ASCII('\r');
+```
+```text
++-------------+-------------+-------------+
+| ASCII('\t') | ASCII('\n') | ASCII('\r') |
++-------------+-------------+-------------+
+| 9 | 10 | 13 |
++-------------+-------------+-------------+
+```
+
+7. Multi-character strings (returns only the first character)
+```sql
+SELECT ASCII('Hello'), ASCII('World123');
+```
+```text
++----------------+------------------+
+| ASCII('Hello') | ASCII('World123') |
++----------------+------------------+
+| 72 | 87 |
++----------------+------------------+
+```
+
+8. UTF-8 multi-byte characters
+```sql
+SELECT ASCII('ṭṛì'), ASCII('ḍḍumai');
+```
+```text
++---------------+------------------+
+| ASCII('ṭṛì') | ASCII('ḍḍumai') |
++---------------+------------------+
+| 225 | 225 |
++---------------+------------------+
+```
+
+9. Mixed numbers and characters
+```sql
+SELECT ASCII('9abc'), ASCII('0xyz');
+```
+```text
++---------------+---------------+
+| ASCII('9abc') | ASCII('0xyz') |
++---------------+---------------+
+| 57 | 48 |
++---------------+---------------+
+```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/auto-partition-name.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/auto-partition-name.md
index aea87ae338a..bd9ddb94652 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/auto-partition-name.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/auto-partition-name.md
@@ -1,100 +1,112 @@
---
{
"title": "AUTO_PARTITION_NAME",
- "language": "zh-CN"
+ "language": "en"
}
---
-:::tip 提示
-该功能自 Apache Doris 2.1.6 版本起支持
-:::
+## Description
+The AUTO_PARTITION_NAME function is used to generate partition names for auto partitions. It supports two modes: RANGE mode generates partition names based on time units, and LIST mode generates partition names based on string values.
-## 语法
+Supported since Apache Doris 2.1.6.
-`VARCHAR AUTO_PARTITION_NAME('RANGE', 'VARCHAR unit', DATETIME datetime)`
+## Syntax
-`VARCHAR AUTO_PARTITION_NAME('LIST', VARCHAR,...)`
+```sql
+AUTO_PARTITION_NAME('RANGE', <unit>, <datetime>)
+AUTO_PARTITION_NAME('LIST', <value>[, <value> ...])
+```
+
+## Parameters
-遵循 RANGE 的分区名规则将 datetime 按照 unit 生成分区名
+| Parameter | Description |
+| ----------- | ----------------------------------------- |
+| `'RANGE'` | RANGE partition mode, generates partition names based on time |
+| `'LIST'` | LIST partition mode, generates partition names based on string values |
+| `<unit>` | Time unit for RANGE mode: `year`, `month`, `day`, `hour`, `minute`, `second`. Type: VARCHAR |
+| `<datetime>` | Datetime value for RANGE mode. Type: DATETIME |
+| `<value>` | Partition value(s) for LIST mode (can be multiple). Type: VARCHAR |
-遵循 LIST 的分区名规则将字符串转换为分区名
+## Return Value
-datetime 参数是合法的日期表达式。
+Returns VARCHAR type, representing the generated partition name.
-unit 参数是您希望的时间间隔,可选的值如下:[`second`,`minute`,`hour`,`day`,`month`,`year`]。
-如果 unit 不符合上述可选值,结果将返回语法错误。
+Special cases:
+- RANGE mode: Partition name format is `pYYYYMMDDHHMMSS`, truncated to the corresponding precision based on unit
+- LIST mode: Partition name format is `p<value><length>`, multiple values separated by length
+- If parameters are invalid, returns an error
-## 举例
+## Examples
+1. Basic usage: RANGE by day
```sql
-mysql> select auto_partition_name('range', 'years', '123');
-ERROR 1105 (HY000): errCode = 2, detailMessage = range auto_partition_name must accept year|month|day|hour|minute|second for 2nd argument
+SELECT auto_partition_name('range', 'day', '2022-12-12 19:20:30');
+```
+```text
++------------------------------------------------------------+
+| auto_partition_name('range', 'day', '2022-12-12 19:20:30') |
++------------------------------------------------------------+
+| p20221212000000 |
++------------------------------------------------------------+
+```
-mysql> select auto_partition_name('range', 'year', '2022-12-12 19:20:30');
-+---------------------------------------------------------------+
-| auto_partition_name('range', 'year', '2022-12-12 19:20:30') |
-+---------------------------------------------------------------+
-| p20220101000000 |
-+---------------------------------------------------------------+
-
-mysql> select auto_partition_name('range', 'month', '2022-12-12 19:20:30');
-+---------------------------------------------------------------+
-| auto_partition_name('range', 'month', '2022-12-12 19:20:30') |
-+---------------------------------------------------------------+
-| p20221201000000 |
-+---------------------------------------------------------------+
-
-mysql> select auto_partition_name('range', 'day', '2022-12-12 19:20:30');
-+---------------------------------------------------------------+
-| auto_partition_name('range', 'day', '2022-12-12 19:20:30') |
-+---------------------------------------------------------------+
-| p20221212000000 |
-+---------------------------------------------------------------+
-
-mysql> select auto_partition_name('range', 'hour', '2022-12-12 19:20:30');
-+---------------------------------------------------------------+
-| auto_partition_name('range', 'hour', '2022-12-12 19:20:30') |
-+---------------------------------------------------------------+
-| p20221212190000 |
-+---------------------------------------------------------------+
-
-mysql> select auto_partition_name('range', 'minute', '2022-12-12 19:20:30');
-+---------------------------------------------------------------+
-| auto_partition_name('range', 'minute', '2022-12-12 19:20:30') |
-+---------------------------------------------------------------+
-| p20221212192000 |
-+---------------------------------------------------------------+
-
-mysql> select auto_partition_name('range', 'second', '2022-12-12 19:20:30');
-+---------------------------------------------------------------+
-| auto_partition_name('range', 'second', '2022-12-12 19:20:30') |
-+---------------------------------------------------------------+
-| p20221212192030 |
-+---------------------------------------------------------------+
-
-mysql> select auto_partition_name('list', 'helloworld');
+2. RANGE by month
+```sql
+SELECT auto_partition_name('range', 'month', '2022-12-12 19:20:30');
+```
+```text
++--------------------------------------------------------------+
+| auto_partition_name('range', 'month', '2022-12-12 19:20:30') |
++--------------------------------------------------------------+
+| p20221201000000 |
++--------------------------------------------------------------+
+```
+
+3. LIST single value
+```sql
+SELECT auto_partition_name('list', 'helloworld');
+```
+```text
+-------------------------------------------+
| auto_partition_name('list', 'helloworld') |
+-------------------------------------------+
| phelloworld10 |
+-------------------------------------------+
+```
-mysql> select auto_partition_name('list', 'hello', 'world');
+4. LIST multiple values
+```sql
+SELECT auto_partition_name('list', 'hello', 'world');
+```
+```text
+-----------------------------------------------+
| auto_partition_name('list', 'hello', 'world') |
+-----------------------------------------------+
| phello5world5 |
+-----------------------------------------------+
+```
-mysql> select auto_partition_name('list', "你好");
-+------------------------------------+
-| auto_partition_name('list', "你好") |
-+------------------------------------+
-| p4f60597d2 |
-+------------------------------------+
+5. UTF-8 special character support: LIST mode
+```sql
+SELECT auto_partition_name('list', 'ṭṛì', 'ḍḍumai');
+```
+```text
++------------------------------------------------+
+| auto_partition_name('list', 'ṭṛì', 'ḍḍumai') |
++------------------------------------------------+
+| pṭṛì9ḍḍumai12 |
++------------------------------------------------+
+```
+
+6. Invalid unit parameter
+```sql
+SELECT auto_partition_name('range', 'years', '2022-12-12');
+```
+```text
+ERROR 1105 (HY000): errCode = 2, detailMessage = range auto_partition_name must accept year|month|day|hour|minute|second for 2nd argument
```
### Keywords
- AUTO_PARTITION_NAME,AUTO,PARTITION,NAME
\ No newline at end of file
+ AUTO_PARTITION_NAME,AUTO,PARTITION,NAME
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/char-length.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/char-length.md
index 4a6326947f4..14079db7181 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/char-length.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/char-length.md
@@ -7,9 +7,9 @@
## Description
-Calculates the length of a string. For multi-byte characters, returns the number of characters.
+The CHAR_LENGTH function calculates the number of characters (not bytes) in a string. For multi-byte characters (such as Chinese characters), it returns the number of characters.
-Currently only supports `utf8` encoding
+Currently only supports UTF-8 encoding.
## Alias
@@ -17,30 +17,71 @@ Currently only supports `utf8` encoding
## Syntax
-```sql
-CHAR_LENGTH ( <str> )
+```sql
+CHAR_LENGTH(<str>)
```
## Parameters
| Parameter | Description |
-|-----------|------------|
-| `<str>` | The string to calculate the length of |
+| ------- | ----------------------------------------- |
+| `<str>` | The string to calculate character length. Type: VARCHAR |
+
+## Return Value
-## Return value
+Returns INT type, representing the number of characters in the string.
-The length of the string <str>.
+Special cases:
+- If the parameter is NULL, returns NULL
+- Empty string returns 0
+- Multi-byte UTF-8 characters each count as 1 character
-## Example
+## Examples
+1. English characters
```sql
-select CHAR_LENGTH("abc"),CHAR_LENGTH("中国")
+SELECT CHAR_LENGTH('hello');
+```
+```text
++----------------------+
+| char_length('hello') |
++----------------------+
+| 5 |
++----------------------+
```
+2. Chinese characters (each Chinese character counts as one character)
+```sql
+SELECT CHAR_LENGTH('中国');
+```
```text
-+-------------------------+----------------------------+
-| character_length('abc') | character_length('中国') |
-+-------------------------+----------------------------+
-| 3 | 2 |
-+-------------------------+----------------------------+
-```
\ No newline at end of file
++----------------------+
+| char_length('中国') |
++----------------------+
+| 2 |
++----------------------+
+```
+
+3. NULL value handling
+```sql
+SELECT CHAR_LENGTH(NULL);
+```
+```text
++--------------------+
+| char_length(NULL) |
++--------------------+
+| NULL |
++--------------------+
+```
+
+4. Comparison with LENGTH function (LENGTH returns byte count)
+```sql
+SELECT CHAR_LENGTH('中国') AS char_len, LENGTH('中国') AS byte_len;
+```
+```text
++----------+----------+
+| char_len | byte_len |
++----------+----------+
+| 2 | 6 |
++----------+----------+
+```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/char.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/char.md
index 4bf7c57e61a..3108a4422c2 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/char.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/char.md
@@ -7,51 +7,75 @@
## Description
-Interpret each argument as an integer and return a string consisting of the characters given by the code values of those integers. Special cases:
-
-- If the result string is illegal for the given character set, the corresponding conversion result is NULL.
-
-- Arguments greater than `255` are converted to multiple result bytes. For example, `char(15049882)` is equivalent to `char(229, 164, 154)`.
-
-## Description
-
-Interpret each argument as an integer and return a string consisting of the characters given by the code values of those integers. Special cases:
-
-- If the result string is illegal for the given character set, the corresponding conversion results in the value NULL.
-
-- Arguments greater than `255` are converted to multiple result bytes. For example, `char(15049882)` is equivalent to `char(229, 164, 154)`.
+The CHAR function interprets each argument as an integer and returns a string consisting of the characters represented by those integer code values.
## Syntax
```sql
-CHAR ( <expr> [ , <expr> ... ] [ USING <charset_name> ] )
+CHAR(<expr>[, <expr> ...] [USING <charset_name>])
```
## Parameters
-| Parameters | Description |
-|------------------|---------------------|
-| `<expr>` | Integer to be calculated as a character |
-| `<charset_name>` | Encoding of the return value, currently only supports `utf8` |
+| Parameter | Description |
+| ------------------ | ----------------------------------------- |
+| `<expr>` | Integer code value to be converted to a character. Type: INT |
-## Return value
+## Return Value
-Parameter list `<expr>` A string consisting of the corresponding characters. Special cases:
+Returns VARCHAR type, a string composed of characters corresponding to the argument integer code values.
-- If the result string is illegal for the given character set, the corresponding conversion result is NULL.
+Special cases:
+- If any argument is NULL, returns an empty string
+- If the result string is illegal for the given character set, returns NULL
+- Arguments greater than 255 are converted to multi-byte characters. For example, `CHAR(15049882)` is equivalent to `CHAR(229, 164, 154)`
-- Parameters greater than `255` will be converted to multiple result bytes. For example, `CHAR(15049882)` is equivalent to `CHAR(229, 164, 154)`.
+## Examples
-## Example
+1. Basic usage: ASCII character generation
+```sql
+SELECT CHAR(68, 111, 114, 105, 115);
+```
+```text
++--------------------------------------+
+| char('utf8', 68, 111, 114, 105, 115) |
++--------------------------------------+
+| Doris |
++--------------------------------------+
+```
+2. Multi-byte UTF-8 characters (Chinese)
```sql
-SELECT CHAR(68, 111, 114, 105, 115),CHAR(15049882, 15179199, 14989469),CHAR(255)
+SELECT CHAR(15049882, 15179199, 14989469);
+```
+```text
++--------------------------------------------+
+| char('utf8', 15049882, 15179199, 14989469) |
++--------------------------------------------+
+| 多睿丝 |
++--------------------------------------------+
+```
+
+3. Illegal character returns NULL
+```sql
+SELECT CHAR(255);
+```
+```text
++-------------------+
+| char('utf8', 255) |
++-------------------+
+| NULL |
++-------------------+
```
+4. NULL value handling
+```sql
+SELECT CHAR(NULL);
+```
```text
-+--------------------------------------+--------------------------------------------+-------------------+
-| char('utf8', 68, 111, 114, 105, 115) | char('utf8', 15049882, 15179199, 14989469) | char('utf8', 255) |
-+--------------------------------------+--------------------------------------------+-------------------+
-| Doris | 多睿丝 | NULL |
-+--------------------------------------+--------------------------------------------+-------------------+
-```
\ No newline at end of file
++------------+
+| CHAR(NULL) |
++------------+
+| |
++------------+
+```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/compress.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/compress.md
index d2e5f504b4a..79b1686c719 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/compress.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/compress.md
@@ -6,44 +6,46 @@
---
## Description
-The COMPRESS function is used to compress strings or values into binary data. The compressed data can be decompressed using the UNCOMPRESS function.
+
+The COMPRESS function compresses a string into binary data using the zlib compression algorithm. The compressed data can be decompressed back to the original string using the UNCOMPRESS function.
## Syntax
```sql
-COMPRESS(<uncompressed_str>)
+COMPRESS(<str>)
```
## Parameters
-| Parameters | Description |
-|--------------------|---------------|
-| `<uncompressed_str>` | Uncompressed raw string, parameter type is varchar or string |
-
+| Parameter | Description |
+| -------- | ----------------------------------------- |
+| `<str>` | The string to be compressed. Type: VARCHAR |
## Return Value
-The return string is of the same type as the input `uncompressed_str`
+Returns VARCHAR type, which is the compressed binary data (not human-readable).
-The return string is an unreadable compressed byte stream.
Special cases:
-- `uncompressed_str` Return empty string(`''`) when the input is empty string(`''`)
+- If the parameter is NULL, returns NULL
+- If the input is an empty string `''`, returns an empty string `''`
-## Example
+## Examples
-``` sql
-select uncompress(compress('abc'));
+1. Basic usage: compression and decompression
+```sql
+SELECT uncompress(compress('hello'));
```
```text
-+-----------------------------+
-| uncompress(compress('abc')) |
-+-----------------------------+
-| abc |
-+-----------------------------+
++-------------------------------+
+| uncompress(compress('hello')) |
++-------------------------------+
+| hello |
++-------------------------------+
```
+2. Empty string handling
```sql
-select compress('');
+SELECT compress('');
```
```text
+--------------+
@@ -51,4 +53,28 @@ select compress('');
+--------------+
| |
+--------------+
-```
\ No newline at end of file
+```
+
+3. NULL value handling
+```sql
+SELECT compress(NULL);
+```
+```text
++----------------+
+| compress(NULL) |
++----------------+
+| NULL |
++----------------+
+```
+
+4. UTF-8 character test
+```sql
+SELECT uncompress(compress('ṭṛì'));
+```
+```text
++----------------------------------+
+| uncompress(compress('ṭṛì')) |
++----------------------------------+
+| ṭṛì |
++----------------------------------+
+```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/concat-ws.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/concat-ws.md
index f1850ceb72c..e24dc6ac321 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/concat-ws.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/concat-ws.md
@@ -7,165 +7,161 @@
## Description
-Use the first parameter sep as the connector to concatenate the second parameter and all subsequent parameters (or all strings in one ARRAY or multi ARRAY ) into a string. Special cases:
+The CONCAT_WS function (Concatenate With Separator) concatenates multiple strings or arrays using a specified separator. Unlike the CONCAT function, CONCAT_WS automatically skips NULL values (but not empty strings) and inserts a separator between non-NULL values. This function supports both string arguments and array arguments modes, and is very useful in scenarios such as generating CSV formats, path joining, and tag lists.
-- If the separator is NULL, NULL is returned.
-
-- The `CONCAT_WS` function does not skip empty strings, but skips NULL values.
-- The `CONCAT_WS` function does not skip empty strings in any `ARRAY` parameters, but skips NULL values in `ARRAY`.
-- The `CONCAT_WS` function does not skip NULL parameter if input multi arrays,return empty string.
-- The first parameters must be a `string` type, and the others must be the same type ,belong to the `string` or `ARRAY` type
## Syntax
```sql
-CONCAT_WS ( <sep> , <str> [ , <str> ] )
-CONCAT_WS ( <sep> , <array> [ , <array> ])
+-- String mode
+CONCAT_WS(<sep>, <str> [, <str> ...])
+
+-- Array mode
+CONCAT_WS(<sep>, <array> [, <array> ...])
```
## Parameters
-| Parameter | Description |
+| Parameter | Description |
|-------|-----------------|
-| `<sep>` | Connector for concatenating strings, it is `string` type or `varchar` type |
-| `<str>` | String to be concatenated , it is `string` or `varchar` type|
-| `<array>` | Array to be concatenated ,it is `ARRAY` type, and every element is `string` or `varchar` type|
+| `<sep>` | Separator string used to join parts. Type: VARCHAR |
+| `<str>` | String arguments to be concatenated. Type: VARCHAR |
+| `<array>` | Array arguments to be concatenated, array elements must be string type. Type: ARRAY<VARCHAR> |
-## Return value
+## Return Value
-Parameter `<sep>` or `<array>` The string concatenated with `<str>`. Special cases:
+Returns VARCHAR type, representing the concatenated string with separators.
-- If delimiter is NULL, returns NULL.
-- If parameters with mutlti arrays and it contains a null,function will return empty string.
+Concatenation rules:
+- Uses the first argument as the separator to join subsequent arguments
+- Automatically skips NULL values, but preserves empty strings
+- Supports string arguments or array arguments, but cannot be mixed
+- Supports UTF-8 multi-byte characters as separators and content
-## Example
+Special cases:
+- If the separator is NULL, returns NULL
+- If all arguments to be concatenated are NULL, returns an empty string
+- In array mode, skips NULL elements in arrays, but preserves empty string elements
+- When NULL arrays are included in multiple array arguments, returns an empty string
+- Mixing string arguments and array arguments is not allowed
-Concatenate strings together using or
+## Examples
+1. Basic string concatenation
```sql
-SELECT CONCAT_WS("or", "d", "is"),CONCAT_WS(NULL, "d", "is"),CONCAT_WS('or', 'd', NULL, 'is')
+SELECT CONCAT_WS(',', 'apple', 'banana', 'orange'), CONCAT_WS('-', 'hello', 'world');
```
-
```text
-+----------------------------+----------------------------+------------------------------------------+
-| concat_ws('or', 'd', 'is') | concat_ws(NULL, 'd', 'is') | concat_ws('or', 'd', NULL, 'is') |
-+----------------------------+----------------------------+------------------------------------------+
-| doris | NULL | doris |
-+----------------------------+----------------------------+------------------------------------------+
++-------------------------------------------+----------------------------------+
+| CONCAT_WS(',', 'apple', 'banana', 'orange') | CONCAT_WS('-', 'hello', 'world') |
++-------------------------------------------+----------------------------------+
+| apple,banana,orange | hello-world |
++-------------------------------------------+----------------------------------+
```
-Concatenate array arrays together using or
-
+2. NULL separator handling
```sql
-SELECT CONCAT_WS("or", ["d", "is"]),CONCAT_WS(NULL, ["d", "is"]),CONCAT_WS("or", ["d", NULL,"is"])
+SELECT CONCAT_WS(NULL, 'd', 'is'), CONCAT_WS('or', 'd', NULL, 'is');
```
-
```text
-+------------------------------+------------------------------+------------------------------------+
-| concat_ws('or', ['d', 'is']) | concat_ws(NULL, ['d', 'is']) | concat_ws('or', ['d', NULL, 'is']) |
-+------------------------------+------------------------------+------------------------------------+
-| doris | NULL | doris |
-+------------------------------+------------------------------+------------------------------------+
++----------------------------+----------------------------------+
+| CONCAT_WS(NULL, 'd', 'is') | CONCAT_WS('or', 'd', NULL, 'is') |
++----------------------------+----------------------------------+
+| NULL | doris |
++----------------------------+----------------------------------+
```
-Concatenating multiple arrays
-
+3. Empty string handling (preserves empty strings)
```sql
-mysql> SELECT CONCAT_WS("-", ["a", "b"], ["c", NULL], ["d"]);
-
-+------------------------------------------------+
-| CONCAT_WS("-", ["a", "b"], ["c", NULL], ["d"]) |
-+------------------------------------------------+
-| a-b-c-d |
-+------------------------------------------------+
+SELECT CONCAT_WS('|', 'hello', '', 'world', NULL), CONCAT_WS(',', '', 'test', '');
+```
+```text
++--------------------------------------------+-------------------------------+
+| CONCAT_WS('|', 'hello', '', 'world', NULL) | CONCAT_WS(',', '', 'test', '') |
++--------------------------------------------+-------------------------------+
+| hello||world | ,test, |
++--------------------------------------------+-------------------------------+
```
-Handling NULL in string parameters
+4. All NULL values
+```sql
+SELECT CONCAT_WS('x', NULL, NULL), CONCAT_WS('-', NULL, NULL, NULL);
+```
+```text
++----------------------------+---------------------------------+
+| CONCAT_WS('x', NULL, NULL) | CONCAT_WS('-', NULL, NULL, NULL) |
++----------------------------+---------------------------------+
+| | |
++----------------------------+---------------------------------+
+```
+5. Array mode basic usage
```sql
-mysql> SELECT CONCAT_WS("|", "hello", "", "world", NULL);
+SELECT CONCAT_WS('or', ['d', 'is']), CONCAT_WS('-', ['apple', 'banana', 'cherry']);
+```
+```text
++------------------------------+--------------------------------------------+
+| CONCAT_WS('or', ['d', 'is']) | CONCAT_WS('-', ['apple', 'banana', 'cherry']) |
++------------------------------+--------------------------------------------+
+| doris | apple-banana-cherry |
++------------------------------+--------------------------------------------+
+```
-+--------------------------------------------+
-| CONCAT_WS("|", "hello", "", "world", NULL) |
-+--------------------------------------------+
-| hello||world |
-+--------------------------------------------+
+6. NULL values in arrays
+```sql
+SELECT CONCAT_WS('or', ['d', NULL, 'is']), CONCAT_WS(',', [NULL, 'a', 'b', NULL, 'c']);
+```
+```text
++------------------------------------+------------------------------------------+
+| CONCAT_WS('or', ['d', NULL, 'is']) | CONCAT_WS(',', [NULL, 'a', 'b', NULL, 'c']) |
++------------------------------------+------------------------------------------+
+| doris | a,b,c |
++------------------------------------+------------------------------------------+
```
-Return empty if NULL in multi arrays;
+7. Multiple array concatenation
+```sql
+SELECT CONCAT_WS('-', ['a', 'b'], ['c', NULL], ['d']), CONCAT_WS('|', ['x'], ['y', 'z']);
+```
+```text
++------------------------------------------------+----------------------------------+
+| CONCAT_WS('-', ['a', 'b'], ['c', NULL], ['d']) | CONCAT_WS('|', ['x'], ['y', 'z']) |
++------------------------------------------------+----------------------------------+
+| a-b-c-d | x|y|z |
++------------------------------------------------+----------------------------------+
+```
+8. NULL array in multiple arrays
```sql
-mysql> SELECT CONCAT_WS("-", ["a", "b"], null,["c", NULL], ["d"]);
+SELECT CONCAT_WS('-', ['a', 'b'], NULL, ['c', NULL], ['d']);
+```
+```text
+-----------------------------------------------------+
-| CONCAT_WS("-", ["a", "b"], null,["c", NULL], ["d"]) |
+| CONCAT_WS('-', ['a', 'b'], NULL, ['c', NULL], ['d']) |
+-----------------------------------------------------+
| |
+-----------------------------------------------------+
```
-Mixing strings and arrays (invalid)
-
-```sql
-mysql> SELECT CONCAT_WS(",", "a", ["b", "c"]);
-
-ERROR 1105 (HY000): errCode = 2, detailMessage = can not cast from origin type ARRAY<VARCHAR(1)> to target type=VARCHAR(65533)
-
-```
-
- All NULL inputs
-
- ```sql
- mysql> SELECT CONCAT_WS("x", NULL, NULL);
-
-+----------------------------+
-| CONCAT_WS("x", NULL, NULL) |
-+----------------------------+
-| |
-+----------------------------+
- ```
-
-Chiese Charactors concat
-
+9. UTF-8 multi-byte character handling
```sql
-mysql> SELECT CONCAT_WS("x", '中文', '中文');
-
-+------------------------------------+
-| CONCAT_WS("x", '中文', '中文') |
-+------------------------------------+
-| 中文x中文 |
-+------------------------------------+
+SELECT CONCAT_WS('x', 'ṭṛì', 'ḍḍumai'), CONCAT_WS('→', ['ṭṛì', 'ḍḍumai', 'hello']);
```
-
-Chinese charactors in multi arrays
-
-```sql
-mysql> SELECT CONCAT_WS("x", ['中文'], ['中文']);
-+----------------------------------------+
-| CONCAT_WS("x", ['中文'], ['中文']) |
-+----------------------------------------+
-| 中文x中文 |
-+----------------------------------------+
+```text
++-------------------------------+----------------------------------------------+
+| CONCAT_WS('x', 'ṭṛì', 'ḍḍumai') | CONCAT_WS('→', ['ṭṛì', 'ḍḍumai', 'hello']) |
++-------------------------------+----------------------------------------------+
+| ṭṛìxḍḍumai | ṭṛì→ḍḍumai→hello |
++-------------------------------+----------------------------------------------+
```
-Insert and concat them
-
+10. CSV format generation and path joining
```sql
-DROP TABLE IF EXISTS test_concat_ws_1;
-
-CREATE TABLE test_concat_ws_1 (id INT, a ARRAY<VARCHAR>, b ARRAY<VARCHAR>) ENGINE=OLAP DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES ('replication_num' = '1')
-
-INSERT INTO test_concat_ws_1 VALUES (1, ['a','b'], ['css',null,'d']), (2, ['x',null], ['y','z']),(3,['你好','世界'],['Doris',null,'Nereids'])
-
-SELECT concat_ws('-', a, b) FROM test_concat_ws_1 ORDER BY id
-
+SELECT CONCAT_WS(',', 'Name', 'Age', 'City'), CONCAT_WS('/', 'home', 'user', 'documents', 'file.txt');
```
-
```text
-
-+-----------------------------+
-| concat_ws('-', a, b) |
-+-----------------------------+
-| a-b-css-d |
-| x-y-z |
-| 你好-世界-Doris-Nereids |
-+-----------------------------+
-```
\ No newline at end of file
++------------------------------------+--------------------------------------------------------+
+| CONCAT_WS(',', 'Name', 'Age', 'City') | CONCAT_WS('/', 'home', 'user', 'documents', 'file.txt') |
++------------------------------------+--------------------------------------------------------+
+| Name,Age,City | home/user/documents/file.txt |
++------------------------------------+--------------------------------------------------------+
+```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/concat.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/concat.md
index 7e826cc51a0..be9b692f446 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/concat.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/concat.md
@@ -7,38 +7,130 @@
## Description
-Concatenates multiple strings. Special cases:
-
-- If any of the parameter values is NULL, the result returned is NULL
+The CONCAT function concatenates multiple strings in sequence into one string. This function supports a variable number of arguments and is one of the most basic and commonly used functions in string processing. It is widely used in scenarios such as data concatenation, report generation, and dynamic SQL construction. Note that if any argument is NULL, the entire result will be NULL.
## Syntax
```sql
-CONCAT ( <expr> [ , <expr> ... ] )
+CONCAT(<expr> [, <expr> ...])
```
## Parameters
-| Parameter | Description |
-|-----------|--------------|
-| `<expr>` | The strings to be concatenated |
+| Parameter | Description |
+|----------|--------------|
+| `<expr>` | String expression to be concatenated, can be a string constant, column name, or other expression. Type: VARCHAR |
+
+## Return Value
-## Return value
+Returns VARCHAR type, representing the concatenated string of all arguments.
-Parameter list `<expr>` The strings to be concatenated. Special cases:
+Concatenation rules:
+- Concatenates strings in argument order
+- Supports any number of arguments (at least 1)
+- Supports correct concatenation of UTF-8 multi-byte characters
+- Numbers and other types are automatically converted to strings
-- If any of the parameter values is NULL, the result returned is NULL
+Special cases:
+- If any argument is NULL, returns NULL (this is the main difference from CONCAT_WS)
+- If no arguments are provided, syntax error
+- Empty string arguments do not affect the concatenation result
+- Supports mixing with non-string types
-## Example
+## Examples
+1. Basic string concatenation
```sql
-SELECT CONCAT("a", "b"),CONCAT("a", "b", "c"),CONCAT("a", null, "c")
+SELECT CONCAT('a', 'b'), CONCAT('a', 'b', 'c');
+```
+```text
++------------------+-----------------------+
+| CONCAT('a', 'b') | CONCAT('a', 'b', 'c') |
++------------------+-----------------------+
+| ab | abc |
++------------------+-----------------------+
```
+2. NULL value handling (key feature)
+```sql
+SELECT CONCAT('a', NULL, 'c'), CONCAT('hello', NULL);
+```
```text
-+------------------+-----------------------+------------------------+
-| concat('a', 'b') | concat('a', 'b', 'c') | concat('a', NULL, 'c') |
-+------------------+-----------------------+------------------------+
-| ab | abc | NULL |
-+------------------+-----------------------+------------------------+
-```
\ No newline at end of file
++------------------------+---------------------+
+| CONCAT('a', NULL, 'c') | CONCAT('hello', NULL) |
++------------------------+---------------------+
+| NULL | NULL |
++------------------------+---------------------+
+```
+
+3. Empty string handling
+```sql
+SELECT CONCAT('hello', '', 'world'), CONCAT('', 'test', '');
+```
+```text
++-----------------------------+------------------------+
+| CONCAT('hello', '', 'world') | CONCAT('', 'test', '') |
++-----------------------------+------------------------+
+| helloworld | test |
++-----------------------------+------------------------+
+```
+
+4. Mixed numbers and strings
+```sql
+SELECT CONCAT('User', 123), CONCAT('Price: $', 99.99);
+```
+```text
++---------------------+---------------------------+
+| CONCAT('User', 123) | CONCAT('Price: $', 99.99) |
++---------------------+---------------------------+
+| User123 | Price: $99.99 |
++---------------------+---------------------------+
+```
+
+5. Multiple argument concatenation
+```sql
+SELECT CONCAT('A', 'B', 'C', 'D', 'E'), CONCAT('1', '2', '3', '4', '5');
+```
+```text
++----------------------------------+----------------------------------+
+| CONCAT('A', 'B', 'C', 'D', 'E') | CONCAT('1', '2', '3', '4', '5') |
++----------------------------------+----------------------------------+
+| ABCDE | 12345 |
++----------------------------------+----------------------------------+
+```
+
+6. UTF-8 multi-byte character concatenation
+```sql
+SELECT CONCAT('ṭṛì', ' ', 'ḍḍumai'), CONCAT('Hello', ' ', 'ṭṛì', ' ', 'ḍḍumai');
+```
+```text
++------------------------------+--------------------------------------+
+| CONCAT('ṭṛì', ' ', 'ḍḍumai') | CONCAT('Hello', ' ', 'ṭṛì', ' ', 'ḍḍumai') |
++------------------------------+--------------------------------------+
+| ṭṛì ḍḍumai | Hello ṭṛì ḍḍumai |
++------------------------------+--------------------------------------+
+```
+
+7. Path and URL construction
+```sql
+SELECT CONCAT('/home/', 'user/', 'file.txt'), CONCAT('https://', 'www.example.com', '/api');
+```
+```text
++--------------------------------------+----------------------------------------------+
+| CONCAT('/home/', 'user/', 'file.txt') | CONCAT('https://', 'www.example.com', '/api') |
++--------------------------------------+----------------------------------------------+
+| /home/user/file.txt | https://www.example.com/api |
++--------------------------------------+----------------------------------------------+
+```
+
+8. Email address construction
+```sql
+SELECT CONCAT('user', '@', 'example.com'), CONCAT('admin.', 'support', '@', 'company.org');
+```
+```text
++------------------------------------+-----------------------------------------------+
+| CONCAT('user', '@', 'example.com') | CONCAT('admin.', 'support', '@', 'company.org') |
++------------------------------------+-----------------------------------------------+
+| user@example.com | admin.support@company.org |
++------------------------------------+-----------------------------------------------+
+```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/count_substrings.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/count_substrings.md
index 77cac5fecd4..b39cb54f405 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/count_substrings.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/count_substrings.md
@@ -96,15 +96,28 @@ SELECT count_substrings('a,b,c,abcde', '');
6. Using the start position parameter
```sql
-SELECT count_substrings('你好,世界!你好,世界!', '世界', 1),
- count_substrings('你好,世界!你好,世界!', '世界', 6);
+SELECT count_substrings('ṭṛì ḍḍumai ṭṛì ti ḍḍumannàri', 'ḍḍu', 1),
+ count_substrings('ṭṛì ḍḍumai ṭṛì ti ḍḍumannàri', 'ḍḍu', 6);
```
```text
-+-----------------------------------------------------------------------+-----------------------------------------------------------------------+
-| count_substrings('你好,世界!你好,世界!', '世界', 1) | count_substrings('你好,世界!你好,世界!', '世界', 6) |
-+-----------------------------------------------------------------------+-----------------------------------------------------------------------+
-| 2 | 1 |
-+-----------------------------------------------------------------------+-----------------------------------------------------------------------+
++-----------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+
+| count_substrings('ṭṛì ḍḍumai ṭṛì ti ḍḍumannàri', 'ḍḍu', 1) | count_substrings('ṭṛì ḍḍumai ṭṛì ti ḍḍumannàri', 'ḍḍu', 6) |
++-----------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+
+| 2 | 1 |
++-----------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+
+```
+
+7. Start position out of range
+```sql
+SELECT count_substrings('éèêëìíîïðñòó éèêëìíîïðñòó', 'éèê', 0),
+ count_substrings('éèêëìíîïðñòó éèêëìíîïðñòó', 'éèê', 30);
+```
+```text
++------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+
+| count_substrings('éèêëìíîïðñòó éèêëìíîïðñòó', 'éèê', 0) | count_substrings('éèêëìíîïðñòó éèêëìíîïðñòó', 'éèê', 30) |
++------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+
+| 0 | 0 |
++------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+
```
7. Start position out of range
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/digital-masking.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/digital-masking.md
index e1c3a4eec42..07b4810c49f 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/digital-masking.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/digital-masking.md
@@ -7,34 +7,87 @@
## Description
-The `digital_masking` function is used for masking numbers. Based on the specified masking rule, certain characters in the number are replaced with *. This function is an alias for the original function `concat(left(id, 3), '****', right(id, 4))`.
+The DIGITAL_MASKING function performs masking on numeric strings by replacing the middle part with `****` in a fixed format, keeping the first 3 digits and last 4 digits. Equivalent to `CONCAT(LEFT(id, 3), '****', RIGHT(id, 4))`.
## Syntax
```sql
-DIGITAL_MASKING( <digital_number> )
+DIGITAL_MASKING(<digital_number>)
```
## Parameters
| Parameter | Description |
-| -- | -- |
-| `<digital_number>` | The digital string that needs to be masked |
+| ------------------ | ----------------------------------------- |
+| `<digital_number>` | The numeric string to be masked. Type: VARCHAR |
## Return Value
-Returns the masked digital string.
+Returns VARCHAR type, representing the masked numeric string.
+
+Special cases:
+- If the parameter is NULL, returns NULL
+- Masking format: first 3 digits + `****` + last 4 digits
+- When string length is less than 7 digits, the result may overlap
## Examples
+1. Basic usage: Mask an 11-digit phone number
+```sql
+SELECT digital_masking('13812345678');
+```
+```text
++--------------------------------+
+| digital_masking('13812345678') |
++--------------------------------+
+| 138****5678 |
++--------------------------------+
+```
+
+2. Numbers of different lengths
```sql
-select digital_masking(13812345678);
+SELECT digital_masking('1234567890');
+```
+```text
++-------------------------------+
+| digital_masking('1234567890') |
++-------------------------------+
+| 123****7890 |
++-------------------------------+
```
+3. Short number (less than 7 digits)
+```sql
+SELECT digital_masking('123');
+```
+```text
++------------------------+
+| digital_masking('123') |
++------------------------+
+| 123****123 |
++------------------------+
+```
+
+4. NULL value handling
+```sql
+SELECT digital_masking(NULL);
+```
+```text
++-----------------------+
+| digital_masking(NULL) |
++-----------------------+
+| NULL |
++-----------------------+
+```
+
+5. String with UTF-8 characters
+```sql
+SELECT digital_masking('13812ṭṛ34678');
```
-+------------------------------+
-| digital_masking(13812345678) |
-+------------------------------+
-| 138****5678 |
-+------------------------------+
+```text
++-------------------------------------+
+| digital_masking('13812ṭṛ34678') |
++-------------------------------------+
+| 138****4678 |
++-------------------------------------+
```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/elt.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/elt.md
index 32222d11524..f8d3565c82f 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/elt.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/elt.md
@@ -7,39 +7,133 @@
## Description
-Returns a string at the specified index. Special cases:
-
-- If there is no string at the specified index, NULL is returned.
+The ELT function returns the string at the specified index position. Index counting starts from 1.
## Syntax
```sql
-ELT ( <pos> , <str> [ , <str> ] )
+ELT(<pos>, <str>[, <str> ...])
```
## Parameters
| Parameter | Description |
-|-----------|------------|
-| `<pos>` | Specified index value |
-| `<str>` | String to be indexed |
+| -------- | ----------------------------------------- |
+| `<pos>` | Index position (starting from 1). Type: INT |
+| `<str>` | String list. Type: VARCHAR |
+
+## Return Value
+
+Returns VARCHAR type, representing the string at the specified index position.
-## Return value
+Special cases:
+- If `<pos>` is less than 1 or greater than the number of strings, returns NULL
+- If `<pos>` is NULL, returns NULL
+- Index starts from 1, the first string has index 1
+
+## Examples
+
+1. Basic usage: Get the 1st string
+```sql
+SELECT ELT(1, 'aaa', 'bbb', 'ccc');
+```
+```text
++-----------------------------+
+| elt(1, 'aaa', 'bbb', 'ccc') |
++-----------------------------+
+| aaa |
++-----------------------------+
+```
+
+2. Get the 2nd string
+```sql
+SELECT ELT(2, 'aaa', 'bbb', 'ccc');
+```
+```text
++-----------------------------+
+| elt(2, 'aaa', 'bbb', 'ccc') |
++-----------------------------+
+| bbb |
++-----------------------------+
+```
-Parameter `<str>` String to be indexed. Special cases:
+3. Index out of bounds returns NULL
+```sql
+SELECT ELT(0, 'aaa', 'bbb'), ELT(5, 'aaa', 'bbb');
+```
+```text
++----------------------+----------------------+
+| elt(0, 'aaa', 'bbb') | elt(5, 'aaa', 'bbb') |
++----------------------+----------------------+
+| NULL | NULL |
++----------------------+----------------------+
+```
-- If there is no string at the specified index, NULL is returned.
+4. NULL value handling
+```sql
+SELECT ELT(NULL, 'aaa', 'bbb');
+```
+```text
++-------------------------+
+| elt(NULL, 'aaa', 'bbb') |
++-------------------------+
+| NULL |
++-------------------------+
+```
+
+5. Index exceeds range returns NULL
+
+```sql
+SELECT ELT(5, 'aaa', 'bbb', 'ccc');
+```
+
+```text
++-----------------------------+
+| elt(5, 'aaa', 'bbb', 'ccc') |
++-----------------------------+
+| NULL |
++-----------------------------+
+```
+
+6. Negative index returns NULL
+
+```sql
+SELECT ELT(-1, 'first', 'second');
+```
+
+```text
++----------------------------+
+| elt(-1, 'first', 'second') |
++----------------------------+
+| NULL |
++----------------------------+
+```
+
+7. UTF-8 string
+
+```sql
+SELECT
+ ELT(2, 'Hello', 'ṭṛ', 'Hola');
+```
+
+```text
++-----------------------------------+
+| ELT(2, 'Hello', 'ṭṛ', 'Hola') |
++-----------------------------------+
+| ṭṛ |
++-----------------------------------+
+```
-## Example
+8. Handling empty strings
```sql
-SELECT ELT(1, 'aaa', 'bbb'),ELT(2, 'aaa', 'bbb'), ELT(0, 'aaa', 'bbb'),ELT(2, 'aaa', 'bbb')
+SELECT ELT(2, 'first', '', 'third');
```
```text
-+----------------------+----------------------+----------------------+----------------------+
-| elt(1, 'aaa', 'bbb') | elt(2, 'aaa', 'bbb') | elt(0, 'aaa', 'bbb') | elt(2, 'aaa', 'bbb') |
-+----------------------+----------------------+----------------------+----------------------+
-| aaa | bbb | NULL | bbb |
-+----------------------+----------------------+----------------------+----------------------+
++------------------------------+
+| elt(2, 'first', '', 'third') |
++------------------------------+
+| |
++------------------------------+
```
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/ends-with.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/ends-with.md
index 9331f4dd7b6..35bd95f4417 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/ends-with.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/ends-with.md
@@ -7,39 +7,155 @@
## Description
-Returns true if the string ends with the specified suffix, otherwise returns false. Special cases:
-
-- If either of the two parameters is NULL, returns NULL.
+The ENDS_WITH function checks whether a string ends with the specified suffix.
## Syntax
```sql
-ENDS_WITH ( <str> , <suffix> )
+ENDS_WITH(<str>, <suffix>)
```
## Parameters
| Parameter | Description |
-|-----------|--------------|
-| `str` | Specifies the original string to be judged |
-| `suffix` | Specifies the ending string to be judged |
+|----------|--------------|
+| `str` | The main string to check. Type: VARCHAR |
+| `suffix` | The suffix string to match. Type: VARCHAR |
+
+## Return Value
-## Return value
+Returns BOOLEAN type (displayed as TINYINT in Doris, where 1 represents true and 0 represents false).
-true or false, type is `BOOLEAN`. Special cases:
+Matching rules:
+- Exact suffix match, case-sensitive
+- Empty suffix matches any string (returns true)
+- Supports correct matching of UTF-8 multi-byte characters
+- Suffix length cannot exceed main string length (unless suffix is empty)
-- If either of the two parameters is NULL, returns NULL.
+Special cases:
+- If either parameter is NULL, returns NULL
+- If suffix is an empty string, returns true (any string ends with an empty string)
+- If main string is empty but suffix is not, returns false
+- If both are empty strings, returns true
-## Example
+## Examples
+1. Basic suffix matching
```sql
-SELECT ENDS_WITH("Hello doris", "doris"),ENDS_WITH("Hello doris", "Hello")
+SELECT ENDS_WITH('Hello doris', 'doris'), ENDS_WITH('Hello doris', 'Hello');
```
-
```text
+-----------------------------------+-----------------------------------+
-| ends_with('Hello doris', 'doris') | ends_with('Hello doris', 'Hello') |
+| ENDS_WITH('Hello doris', 'doris') | ENDS_WITH('Hello doris', 'Hello') |
+-----------------------------------+-----------------------------------+
| 1 | 0 |
+-----------------------------------+-----------------------------------+
+```
+
+2. Case sensitivity
+```sql
+SELECT ENDS_WITH('Hello World', 'world'), ENDS_WITH('Hello World', 'World');
+```
+```text
++-----------------------------------+-----------------------------------+
+| ENDS_WITH('Hello World', 'world') | ENDS_WITH('Hello World', 'World') |
++-----------------------------------+-----------------------------------+
+| 0 | 1 |
++-----------------------------------+-----------------------------------+
+```
+
+3. NULL value handling
+```sql
+SELECT ENDS_WITH(NULL, 'test'), ENDS_WITH('test', NULL);
+```
+```text
++--------------------------+--------------------------+
+| ENDS_WITH(NULL, 'test') | ENDS_WITH('test', NULL) |
++--------------------------+--------------------------+
+| NULL | NULL |
++--------------------------+--------------------------+
+```
+
+4. Empty string handling
+```sql
+SELECT ENDS_WITH('hello', ''), ENDS_WITH('', 'world');
+```
+```text
++-------------------------+--------------------------+
+| ENDS_WITH('hello', '') | ENDS_WITH('', 'world') |
++-------------------------+--------------------------+
+| 1 | 0 |
++-------------------------+--------------------------+
+```
+
+5. Complete string matching
+```sql
+SELECT ENDS_WITH('test', 'test'), ENDS_WITH('testing', 'test');
+```
+```text
++---------------------------+------------------------------+
+| ENDS_WITH('test', 'test') | ENDS_WITH('testing', 'test') |
++---------------------------+------------------------------+
+| 1 | 1 |
++---------------------------+------------------------------+
+```
+
+6. File extension check
+```sql
+SELECT ENDS_WITH('document.pdf', '.pdf'), ENDS_WITH('image.jpg', '.png');
+```
+```text
++------------------------------------+----------------------------------+
+| ENDS_WITH('document.pdf', '.pdf') | ENDS_WITH('image.jpg', '.png') |
++------------------------------------+----------------------------------+
+| 1 | 0 |
++------------------------------------+----------------------------------+
+```
+
+7. UTF-8 multi-byte characters
+```sql
+SELECT ENDS_WITH('hello ṭṛì ḍḍumai', 'ḍḍumai'), ENDS_WITH('hello ṭṛì ḍḍumai', 'ṭṛì');
+```
+```text
++------------------------------------------+---------------------------------------+
+| ENDS_WITH('hello ṭṛì ḍḍumai', 'ḍḍumai') | ENDS_WITH('hello ṭṛì ḍḍumai', 'ṭṛì') |
++------------------------------------------+---------------------------------------+
+| 1 | 0 |
++------------------------------------------+---------------------------------------+
+```
+
+8. URL path check
+```sql
+SELECT ENDS_WITH('https://example.com/api', '/api'), ENDS_WITH('https://example.com/', '.html');
+```
+```text
++--------------------------------------------+---------------------------------------------+
+| ENDS_WITH('https://example.com/api', '/api') | ENDS_WITH('https://example.com/', '.html') |
++--------------------------------------------+---------------------------------------------+
+| 1 | 0 |
++--------------------------------------------+---------------------------------------------+
+```
+
+9. Numeric string suffix
+```sql
+SELECT ENDS_WITH('123456789', '789'), ENDS_WITH('123456789', '456');
+```
+```text
++--------------------------------+--------------------------------+
+| ENDS_WITH('123456789', '789') | ENDS_WITH('123456789', '456') |
++--------------------------------+--------------------------------+
+| 1 | 0 |
++--------------------------------+--------------------------------+
+```
+
+10. Email domain check
+```sql
+SELECT ENDS_WITH('user@gmail.com', '.com'), ENDS_WITH('admin@company.org', '.com');
+```
+```text
++------------------------------------+--------------------------------------+
+| ENDS_WITH('user@gmail.com', '.com') | ENDS_WITH('admin@company.org', '.com') |
++------------------------------------+--------------------------------------+
+| 1 | 0 |
++------------------------------------+--------------------------------------+
```
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/find-in-set.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/find-in-set.md
index 04498fbafec..3a8f147bb52 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/find-in-set.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/find-in-set.md
@@ -7,42 +7,156 @@
## Description
-Returns the position of the first occurrence of str in strlist (counting starts at 1).
-
-strlist is a comma-delimited string. Special cases:
-
-- If not found, returns 0.
-- If any parameter is NULL, returns NULL.
+Returns the position of the first occurrence of string str in the comma-separated string list strlist (counting starts from 1). This function is implemented in MySQL-compatible mode and is used to find specific strings in comma-separated value lists.
## Syntax
```sql
-FIND_IN_SET ( <str> , <strlist> )
+FIND_IN_SET(<str>, <strlist>)
```
## Parameters
-| Parameter | Description |
+| Parameter | Description |
|-------------|----------|
-| `<str>` | String to be searched |
-| `<strlist>` | String to be searched |
+| `<str>` | The target string to search for. Type: VARCHAR |
+| `<strlist>` | The comma-separated string list to search in for str. Type: VARCHAR |
-## Return value
+## Return Value
-The position of the first occurrence of parameter `<str>` in parameter `<strlist>`. Special cases:
+Returns INT type, representing the position of str in strlist (counting starts from 1).
-- If not found, returns 0.
-- If any parameter is NULL, returns NULL.
+Search rules:
+- Exact match: Returns position only when str exactly matches a substring in strlist
+- Position counting starts from 1
+- Returns the position of the first match
-## Example
+Special cases:
+- If str is an empty string, returns 0
+- If strlist is an empty string, returns 0
+- If no match is found, returns 0
+- If any parameter is NULL, returns NULL
+- If str contains a comma, it cannot be matched correctly (because comma is the delimiter)
+- Matching is case-sensitive
+## Examples
+
+1. Basic search
```sql
-SELECT FIND_IN_SET("b", "a,b,c")
+SELECT FIND_IN_SET('b', 'a,b,c');
```
-
```text
-| find_in_set('b', 'a,b,c') |
++---------------------------+
+| FIND_IN_SET('b', 'a,b,c') |
+---------------------------+
| 2 |
+---------------------------+
```
+
+2. Find first element
+```sql
+SELECT FIND_IN_SET('apple', 'apple,banana,cherry');
+```
+```text
++------------------------------------------+
+| FIND_IN_SET('apple', 'apple,banana,cherry') |
++------------------------------------------+
+| 1 |
++------------------------------------------+
+```
+
+3. Find last element
+```sql
+SELECT FIND_IN_SET('cherry', 'apple,banana,cherry');
+```
+```text
++-------------------------------------------+
+| FIND_IN_SET('cherry', 'apple,banana,cherry') |
++-------------------------------------------+
+| 3 |
++-------------------------------------------+
+```
+
+4. No match found
+```sql
+SELECT FIND_IN_SET('orange', 'apple,banana,cherry');
+```
+```text
++--------------------------------------------+
+| FIND_IN_SET('orange', 'apple,banana,cherry') |
++--------------------------------------------+
+| 0 |
++--------------------------------------------+
+```
+
+5. NULL value handling
+```sql
+SELECT FIND_IN_SET(NULL, 'a,b,c'), FIND_IN_SET('b', NULL);
+```
+```text
++---------------------------+-------------------------+
+| FIND_IN_SET(NULL, 'a,b,c') | FIND_IN_SET('b', NULL) |
++---------------------------+-------------------------+
+| NULL | NULL |
++---------------------------+-------------------------+
+```
+
+6. Empty string handling
+```sql
+SELECT FIND_IN_SET('', 'a,b,c'), FIND_IN_SET('a', '');
+```
+```text
++-------------------------+-----------------------+
+| FIND_IN_SET('', 'a,b,c') | FIND_IN_SET('a', '') |
++-------------------------+-----------------------+
+| 0 | 0 |
++-------------------------+-----------------------+
+```
+
+7. String containing comma (cannot match correctly)
+```sql
+SELECT FIND_IN_SET('a,b', 'a,b,c,d');
+```
+```text
++------------------------------+
+| FIND_IN_SET('a,b', 'a,b,c,d') |
++------------------------------+
+| 0 |
++------------------------------+
+```
+
+8. Case-sensitive matching
+```sql
+SELECT FIND_IN_SET('B', 'a,b,c'), FIND_IN_SET('b', 'A,B,C');
+```
+```text
++---------------------------+---------------------------+
+| FIND_IN_SET('B', 'a,b,c') | FIND_IN_SET('b', 'A,B,C') |
++---------------------------+---------------------------+
+| 0 | 0 |
++---------------------------+---------------------------+
+```
+
+9. Partial match will not succeed
+```sql
+SELECT FIND_IN_SET('ap', 'apple,banana,cherry');
+```
+```text
++---------------------------------------+
+| FIND_IN_SET('ap', 'apple,banana,cherry') |
++---------------------------------------+
+| 0 |
++---------------------------------------+
+```
+
+10. Numeric string search
+```sql
+SELECT FIND_IN_SET('2', '1,2,3,10,20');
+```
+```text
++--------------------------------+
+| FIND_IN_SET('2', '1,2,3,10,20') |
++--------------------------------+
+| 2 |
++--------------------------------+
+```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/format-number.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/format-number.md
index afec143ab86..09d3da8b523 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/format-number.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/format-number.md
@@ -7,7 +7,7 @@
## Description
-Returns a formatted string using a unit symbol, UNITS: "K", "M", "B", "T", "Q"
+The FORMAT_NUMBER function formats numerical values into strings with unit symbols. Supported units are: K (thousand), M (million), B (billion), T (trillion), Q (quadrillion).
## Syntax
@@ -15,50 +15,72 @@ Returns a formatted string using a unit symbol, UNITS: "K", "M", "B", "T", "Q"
FORMAT_NUMBER(<val>)
```
-## Parameters
+## Parameters
-| Parameter | Description |
-| -- | -- |
-| `<val>` | The value is to be calculated with unit |
+| Parameter | Description |
+| -------- | ----------------------------------------- |
+| `<val>` | The numerical value to be formatted. Type: DOUBLE |
-## Return Value
+## Return Value
-The formatted string using a unit symbol.
+Returns VARCHAR type, representing the formatted string with unit symbol.
-## Example
+Special cases:
+- If the parameter is NULL, returns NULL
+- Numbers less than 1000 are returned directly without units
+- Unit conversion rules:
+ - K: thousand (1,000)
+ - M: million (1,000,000)
+ - B: billion (1,000,000,000)
+ - T: trillion (1,000,000,000,000)
+ - Q: quadrillion (1,000,000,000,000,000)
+## Examples
+
+1. Basic usage: thousand (K)
```sql
-SELECT format_number(123456.0);
+SELECT format_number(1500);
```
-
```text
-+-----------------------------------------+
-| format_number(cast(123456.0 as DOUBLE)) |
-+-----------------------------------------+
-| 123K |
-+-----------------------------------------+
++---------------------+
+| format_number(1500) |
++---------------------+
+| 1.50K |
++---------------------+
```
+2. Million (M)
```sql
-SELECT format_number(1000000.00);
+SELECT format_number(5000000);
```
-
```text
-+-------------------------------------------+
-| format_number(cast(1000000.00 as DOUBLE)) |
-+-------------------------------------------+
-| 1M |
-+-------------------------------------------+
++------------------------+
+| format_number(5000000) |
++------------------------+
+| 5.00M |
++------------------------+
```
+3. Numbers less than thousand
```sql
-select format_number(-1000000000000000);
+SELECT format_number(999);
+```
+```text
++----------------------------------+
+| format_number(cast(999 as DOUBLE))|
++----------------------------------+
+| 999 |
++----------------------------------+
```
+4. NULL value handling
+```sql
+SELECT format_number(NULL);
+```
```text
-+--------------------------------------------------+
-| format_number(cast(-1000000000000000 as DOUBLE)) |
-+--------------------------------------------------+
-| -1Q |
-+--------------------------------------------------+
++---------------------+
+| format_number(NULL) |
++---------------------+
+| NULL |
++---------------------+
```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/format.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/format.md
index 8049f8bba98..94de134b80f 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/format.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/format.md
@@ -7,59 +7,89 @@
## Description
-Returns a formatted string using the specified [format](https://fmt.dev/11.1/syntax/#format-specification-mini-language) string and arguments:
+The FORMAT function returns a string formatted using the specified format string and parameters. The formatting rules follow the [fmt format specification](https://fmt.dev/11.1/syntax/#format-specification-mini-language).
## Syntax
```sql
-FORMAT(<format>, <args> [, ...])
+FORMAT(<format>, <args>[, ...])
```
-## Parameters
+## Parameters
-| Parameter | Description |
-| -- | -- |
-| `<format>` | The value is to be format mode |
-| `<args>` | The value is to be format within string |
+| Parameter | Description |
+| ---------- | ----------------------------------------- |
+| `<format>` | Format string containing format placeholders. Type: VARCHAR |
+| `<args>` | Parameters to be formatted (can be multiple). Type: ANY |
-## Return Value
+## Return Value
-The formatted string using a format mode.
+Returns VARCHAR type, representing the result formatted according to the format string.
-## Example
+Special cases:
+- If any parameter is NULL, returns NULL
+- Format string uses `{}` as placeholder
+- Supports positional parameters (e.g., `{0}`, `{1}`) and named parameters
+- Supports various format options (alignment, precision, padding, etc.)
+## Examples
+
+1. Basic usage: Format number precision
```sql
-select format("{:.5}",pi());
+SELECT format('{:.2}', pi());
```
-
```text
+-----------------------+
-| format('{:.5}', pi()) |
+| format('{:.2}', pi()) |
+-----------------------+
-| 3.1416 |
+| 3.1 |
+-----------------------+
```
+2. Multiple parameter formatting
```sql
-select format("{:08.2}",pi());
+SELECT format('{0}-{1}', 'hello', 'world');
+```
+```text
++-------------------------------------+
+| format('{0}-{1}', 'hello', 'world') |
++-------------------------------------+
+| hello-world |
++-------------------------------------+
```
+3. Alignment and padding
+```sql
+SELECT format('{:>10}', 123);
+```
```text
-+-------------------------+
-| format('{:08.2}', pi()) |
-+-------------------------+
-| 000003.1 |
-+-------------------------+
++-----------------------+
+| format('{:>10}', 123) |
++-----------------------+
+| 123 |
++-----------------------+
```
+4. NULL value handling
```sql
-select format("{0}-{1}","second","first");
+SELECT format('{:.2}', NULL);
+```
+```text
++-----------------------+
+| format('{:.2}', NULL) |
++-----------------------+
+| NULL |
++-----------------------+
```
+5. UTF-8 string handling
+```sql
+SELECT format('{0}-{1}', 'ṭṛṭṛ', 'ṭṛ');
+```
```text
-+--------------------------------------+
-| format('{0}-{1}', 'second', 'first') |
-+--------------------------------------+
-| second-first |
-+--------------------------------------+
++---------------------------------------------+
+| format('{0}-{1}', 'ṭṛṭṛ', 'ṭṛ') |
++---------------------------------------------+
+| ṭṛṭṛ-ṭṛ |
++---------------------------------------------+
```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/from-base64.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/from-base64.md
index dd8a8e22357..c8ad0bae501 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/from-base64.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/from-base64.md
@@ -7,38 +7,95 @@
## Description
-Returns the result of Base64 decoding the input string. Special cases:
-
-- When the input string is incorrect (a string that is not possible after Base64 encoding appears), NULL will be returned
+The FROM_BASE64 function decodes a Base64-encoded string back to its original string. This is the inverse operation of TO_BASE64 and follows RFC 4648 standards. Base64 encoding is commonly used to transmit binary data in text protocols, and this function can restore the encoded data. It supports standard Base64 character set (A-Z, a-z, 0-9, +, /) and padding character (=).
## Syntax
```sql
-FROM_BASE64 ( <str> )
+FROM_BASE64(<str>)
```
## Parameters
-| Parameters | Description |
-|------------|-----------------|
-| `<str>` | The string to be Base64 decoded |
+| Parameter | Description |
+|---------|-----------------|
+| `<str>` | The Base64-encoded string to decode. Type: VARCHAR |
+
+## Return Value
-## Return value
+Returns VARCHAR type, representing the original string after Base64 decoding.
-Parameter `<str>` The result of Base64 decoding. Special cases:
+Decoding rules:
+- Accepts standard Base64 character set: A-Z, a-z, 0-9, +, /
+- Supports padding character =
+- Follows RFC 4648 standards
+- Automatically ignores whitespace characters (spaces, newlines, etc.)
+- Decoding result may contain non-printable characters
-- When the input string is incorrect (a string that is not possible after Base64 encoding appears), NULL will be returned.
+Special cases:
+- If input is NULL, returns NULL
+- If input contains illegal Base64 characters, returns NULL
+- If input is an empty string, returns an empty string
+- If padding is incorrect or format is invalid, returns NULL
-## Example
+## Examples
+1. Basic decoding
```sql
-SELECT FROM_BASE64('MQ=='),FROM_BASE64('MjM0'),FROM_BASE64(NULL)
+SELECT FROM_BASE64('MQ=='), FROM_BASE64('QQ==');
+```
+```text
++---------------------+---------------------+
+| FROM_BASE64('MQ==') | FROM_BASE64('QQ==') |
++---------------------+---------------------+
+| 1 | A |
++---------------------+---------------------+
```
+2. Multi-character decoding
+```sql
+SELECT FROM_BASE64('MjM0'), FROM_BASE64('SGVsbG8=');
+```
+```text
++---------------------+-------------------------+
+| FROM_BASE64('MjM0') | FROM_BASE64('SGVsbG8=') |
++---------------------+-------------------------+
+| 234 | Hello |
++---------------------+-------------------------+
+```
+
+3. NULL value handling
+```sql
+SELECT FROM_BASE64(NULL);
+```
+```text
++-------------------+
+| FROM_BASE64(NULL) |
++-------------------+
+| NULL |
++-------------------+
+```
+
+4. Empty string handling
+```sql
+SELECT FROM_BASE64('');
+```
+```text
++-----------------+
+| FROM_BASE64('') |
++-----------------+
+| |
++-----------------+
+```
+
+5. Illegal character handling
+```sql
+SELECT FROM_BASE64('!!!'), FROM_BASE64('ABC@DEF');
+```
```text
-+---------------------+---------------------+-------------------+
-| from_base64('MQ==') | from_base64('MjM0') | from_base64(NULL) |
-+---------------------+---------------------+-------------------+
-| 1 | 234 | NULL |
-+---------------------+---------------------+-------------------+
++--------------------+------------------------+
+| FROM_BASE64('!!!') | FROM_BASE64('ABC@DEF') |
++--------------------+------------------------+
+| NULL | NULL |
++--------------------+------------------------+
```
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/hex.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/hex.md
index 4aec2104fba..138980132b7 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/hex.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/hex.md
@@ -7,51 +7,97 @@
## Description
-If the input parameter is a number, return the string representation of the hexadecimal value.
+The HEX function converts input parameters to hexadecimal string representation. This function is MySQL-compatible and supports both numeric and string input types with different conversion rules.
-If the input parameter is a string, convert each character to two hexadecimal characters, concatenate all the converted characters into a string for output.
+If the input parameter is a number (BIGINT type), returns the hexadecimal string representation of that number.
+
+If the input parameter is a string, converts each character (by byte) to two hexadecimal characters, then concatenates all converted characters into the result string.
## Syntax
```sql
-HEX ( <str> )
+HEX(<expr>)
```
## Parameters
| Parameter | Description |
|-------|--------------|
-| `<str>` | Input parameter is a number or a string |
+| `<expr>` | Input parameter, can be BIGINT type number or VARCHAR type string |
+
+## Return Value
+
+Returns VARCHAR type, representing the hexadecimal representation of the input parameter.
-## Return value
+Conversion rules:
+- Numeric input: Converts to corresponding hexadecimal value (within BIGINT range)
+- String input: Each byte converts to two uppercase hexadecimal characters
+- Negative numbers are converted in two's complement binary form
-The hexadecimal result of parameter `<str>`.
+Special cases:
+- If parameter is NULL, returns NULL
+- Number 0 converts to '0'
+- Empty string converts to empty string
+- Negative numbers convert to hexadecimal representation of 64-bit two's complement
-## Example
+## Examples
-The input parameter is a number
+1. Basic number conversion
```sql
-SELECT HEX(12),HEX(-1)
+SELECT HEX(12), HEX(-1);
```
-
```text
+---------+------------------+
-| hex(12) | hex(-1) |
+| HEX(12) | HEX(-1) |
+---------+------------------+
| C | FFFFFFFFFFFFFFFF |
+---------+------------------+
```
-The input parameter is a string
-
+2. String conversion
```sql
-SELECT HEX('1'),HEX('@'),HEX('12')
+SELECT HEX('1'), HEX('@'), HEX('12');
```
-
```text
+----------+----------+-----------+
-| hex('1') | hex('@') | hex('12') |
+| HEX('1') | HEX('@') | HEX('12') |
+----------+----------+-----------+
| 31 | 40 | 3132 |
+----------+----------+-----------+
+```
+
+3. Large integer conversion
+```sql
+SELECT HEX(255), HEX(65535), HEX(16777215);
+```
+```text
++----------+------------+----------------+
+| HEX(255) | HEX(65535) | HEX(16777215) |
++----------+------------+----------------+
+| FF | FFFF | FFFFFF |
++----------+------------+----------------+
+```
+
+4. NULL value handling
+```sql
+SELECT HEX(NULL);
+```
+```text
++-----------+
+| HEX(NULL) |
++-----------+
+| NULL |
++-----------+
+```
+
+5. Zero and empty string
+```sql
+SELECT HEX(0), HEX('');
+```
+```text
++--------+--------+
+| HEX(0) | HEX('') |
++--------+--------+
+| 0 | |
++--------+--------+
```
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/initcap.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/initcap.md
index 3ab8cb13b58..feaa1045b89 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/initcap.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/initcap.md
@@ -7,34 +7,83 @@
## Description
-Capitalizes the first letter of the word contained in the parameter and converts the rest of the letters to lowercase. A word is a sequence of alphanumeric characters separated by non-alphanumeric characters.
+The INITCAP function converts the first letter of each word in a string to uppercase and the remaining letters to lowercase. A word is defined as a sequence of alphanumeric characters separated by non-alphanumeric characters. This function is suitable for formatting names, titles, and other scenarios requiring standard case formatting.
## Syntax
```sql
-INITCAP ( <str> )
+INITCAP(<str>)
```
## Parameters
| Parameter | Description |
-|-----------|-----------|
-| `<str>` | The string to be converted |
+|---------|-----------|
+| `<str>` | The string to convert case format. Type: VARCHAR |
## Return Value
-The result of capitalizing the first letter of the word in the parameter `<str>` and lowering the rest of the letters.
+Returns VARCHAR type, representing the converted string.
-## Example
+Conversion rules:
+- The first letter of each word is converted to uppercase
+- Remaining letters in the word are converted to lowercase
+- Words are separated by non-alphanumeric characters (spaces, punctuation, symbols, etc.)
+- Numeric characters are not case-converted
+- Supports Unicode character case conversion
+Special cases:
+- If parameter is NULL, returns NULL
+- If string is empty, returns empty string
+- Consecutive non-alphanumeric characters are treated as a single separator
+- Letters at the beginning of the string are capitalized
+
+## Examples
+
+1. Basic word capitalization
+```sql
+SELECT INITCAP('hello world');
+```
+```text
++------------------------+
+| INITCAP('hello world') |
++------------------------+
+| Hello World |
++------------------------+
+```
+
+2. Mixed case conversion
+```sql
+SELECT INITCAP('hELLo WoRLD');
+```
+```text
++------------------------+
+| INITCAP('hELLo WoRLD') |
++------------------------+
+| Hello World |
++------------------------+
+```
+
+3. NULL value handling
```sql
-SELECT INITCAP('hello hello.,HELLO123HELlo')
+SELECT INITCAP(NULL);
+```
+```text
++---------------+
+| INITCAP(NULL) |
++---------------+
+| NULL |
++---------------+
```
+4. String with numbers and symbols
+```sql
+SELECT INITCAP('hello hello.,HELLO123HELlo');
+```
```text
+---------------------------------------+
-| initcap('hello hello.,HELLO123HELlo') |
+| INITCAP('hello hello.,HELLO123HELlo') |
+---------------------------------------+
-| Hello Hello.,hello123hello |
+| Hello Hello.,Hello123hello |
+---------------------------------------+
```
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/instr.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/instr.md
index 1f033e731ce..ee06ca563b2 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/instr.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/instr.md
@@ -7,39 +7,84 @@
## Description
-Returns the first occurrence position of substr in str (counting starts from 1). Special cases:
-
-- If substr does not appear in str, returns 0.
+The INSTR function returns the position of the first occurrence of a substring in the main string, with position counting starting from 1. This is a commonly used string search function that supports exact matching and is case-sensitive. The function is widely used in text processing, data cleaning, and string analysis.
## Syntax
```sql
-INSTR ( <str> , <substr> )
+INSTR(<str>, <substr>)
```
## Parameters
| Parameter | Description |
|--------|-----------|
-| `<str>` | String to search for |
-| `<substr>` | String to be searched for |
+| `<str>` | Main string to search within. Type: VARCHAR |
+| `<substr>` | Substring to find. Type: VARCHAR |
+
+## Return Value
-## Return value
+Returns INT type, representing the position of the first occurrence of the substring in the main string.
-Parameters The first occurrence position of `<substr>` in `<str>` (counting starts from 1). Special cases:
+Search rules:
+- Returns position index starting from 1 (not from 0)
+- If substring does not exist, returns 0
+- Search is case-sensitive
+- Supports correct position calculation for UTF-8 multi-byte characters
+- Special handling for empty strings
-- If `<substr>` does not appear in `<str>`, returns 0.
+Special cases:
+- If any parameter is NULL, returns NULL
+- If substring is an empty string, returns 1 (empty string "exists" at any position)
+- If main string is empty but substring is not, returns 0
+- Supports finding substrings containing special characters and symbols
-## Example
+## Examples
+1. Basic character search
```sql
-SELECT INSTR("abc", "b"),INSTR("abc", "d")
+SELECT INSTR('abc', 'b'), INSTR('abc', 'd');
```
-
```text
+-------------------+-------------------+
-| instr('abc', 'b') | instr('abc', 'd') |
+| INSTR('abc', 'b') | INSTR('abc', 'd') |
+-------------------+-------------------+
| 2 | 0 |
+-------------------+-------------------+
+```
+
+2. Substring search
+```sql
+SELECT INSTR('hello world', 'world'), INSTR('hello world', 'WORLD');
+```
+```text
++------------------------------+------------------------------+
+| INSTR('hello world', 'world') | INSTR('hello world', 'WORLD') |
++------------------------------+------------------------------+
+| 7 | 0 |
++------------------------------+------------------------------+
+```
+
+3. NULL value handling
+```sql
+SELECT INSTR(NULL, 'test'), INSTR('test', NULL);
+```
+```text
++---------------------+---------------------+
+| INSTR(NULL, 'test') | INSTR('test', NULL) |
++---------------------+---------------------+
+| NULL | NULL |
++---------------------+---------------------+
+```
+
+4. Empty string handling
+```sql
+SELECT INSTR('hello', ''), INSTR('', 'world');
+```
+```text
++--------------------+---------------------+
+| INSTR('hello', '') | INSTR('', 'world') |
++--------------------+---------------------+
+| 1 | 0 |
++--------------------+---------------------+
```
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/int-to-uuid.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/int-to-uuid.md
index f279b0425a3..0aee687ea43 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/int-to-uuid.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/int-to-uuid.md
@@ -7,25 +7,27 @@
## Description
-For an encoded LARGEINT input, convert it to a raw uuid string.
+For the input encoded LARGEINT, converts it to the original UUID string.
## Syntax
```sql
-INT_TO_UUID ( <int128> )
+INT_TO_UUID(<int128>)
```
## Parameters
-| Parameter | Description |
+| Parameter | Description |
|------------|-----------------|
| `<int128>` | Encoded LARGEINT value |
-## Return value
+## Return Value
-Parameter `<int128>` Raw uuid string.
+Returns the original UUID string of parameter `<int128>`.
-## Example
+- If input is NULL, returns NULL
+
+## Examples
```sql
SELECT INT_TO_UUID(95721955514869408091759290071393952876)
@@ -38,3 +40,15 @@ SELECT INT_TO_UUID(95721955514869408091759290071393952876)
| 6ce4766f-6783-4b30-b357-bba1c7600348 |
+-----------------------------------------------------+
```
+
+```sql
+SELECT INT_TO_UUID(NULL);
+```
+
+```text
++-------------------+
+| INT_TO_UUID(NULL) |
++-------------------+
+| NULL |
++-------------------+
+```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/lcase.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/lcase.md
index 522d7fc12ac..5432f6045c8 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/lcase.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/lcase.md
@@ -7,51 +7,69 @@
## Description
-Convert all strings in the parameter to lowercase.
-
-## Alias
-
-- LOWER
+The LCASE function (alias LOWER) converts all uppercase letters in a string to lowercase.
## Syntax
```sql
-LCASE ( <str> )
-LOWER ( <str> )
+LCASE(<str>)
+LOWER(<str>)
```
## Parameters
| Parameter | Description |
-|-----------|--------------|
-| `<str>` | String to be converted to lowercase |
+|---------|--------------|
+| `<str>` | The string to convert to lowercase. Type: VARCHAR |
## Return Value
-Parameter `<str>` String converted to lowercase
+Returns VARCHAR type, representing the string after conversion to lowercase.
+
+Conversion rules:
+- Converts all uppercase letters in the string to their corresponding lowercase letters
+- Non-letter characters (numbers, symbols, spaces, etc.) remain unchanged
+- Letters that are already lowercase remain unchanged
-## Example
+Special cases:
+- If parameter is NULL, returns NULL
+- If string is empty, returns empty string
+- If string contains no uppercase letters, returns original string
+## Examples
+
+1. Basic English letter conversion
```sql
-SELECT LCASE("AbC123"),LOWER("AbC123")
+SELECT LOWER('AbC123'), LCASE('AbC123');
```
-
```text
+-----------------+-----------------+
-| lower('AbC123') | lower('AbC123') |
+| LOWER('AbC123') | LCASE('AbC123') |
+-----------------+-----------------+
| abc123 | abc123 |
+-----------------+-----------------+
```
+2. Mixed character handling
```sql
-SELECT LOWER("ҚAZAҚ123"),LCASE("ҒАРЫШ");
+SELECT LOWER('Hello World!'), LCASE('TEST@123');
+```
+```text
++----------------------+------------------+
+| LOWER('Hello World!') | LCASE('TEST@123') |
++----------------------+------------------+
+| hello world! | test@123 |
++----------------------+------------------+
```
+3. NULL value handling
+```sql
+SELECT LOWER(NULL), LCASE(NULL);
+```
```text
-+---------------------+---------------------+
-| LOWER("ҚAZAҚ123") | LCASE("ҒАРЫШ") |
-+---------------------+---------------------+
-| қazaқ123 | ғарыш |
-+---------------------+---------------------+
++-------------+-------------+
+| LOWER(NULL) | LCASE(NULL) |
++-------------+-------------+
+| NULL | NULL |
++-------------+-------------+
```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/length.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/length.md
index 5519407badb..cc967f8ebfc 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/length.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/length.md
@@ -7,46 +7,72 @@
## Description
-Returns the number of bytes in a string or a binary string.
+The LENGTH function returns the byte length of a string (in bytes). This function calculates the number of bytes a string occupies in UTF-8 encoding, not the number of characters.
+
+**Note the difference from CHAR_LENGTH:**
+- `LENGTH()` returns the number of bytes
+- `CHAR_LENGTH()` and `CHARACTER_LENGTH()` return the number of characters
+- For ASCII characters, byte count equals character count
+- For multi-byte characters (such as Chinese, emoji), byte count is usually greater than character count
+
+## Alias
+- `OCTET_LENGTH()`
## Syntax
```sql
-LENGTH ( <str> )
+LENGTH(<str>)
```
## Parameters
| Parameter | Description |
-|-----------| --------------- |
-| `<str>` | The string or binary string whose bytes need to be calculated |
+|---------|---------------|
+| `<str>` | The string whose byte length needs to be calculated. Type: VARCHAR |
## Return Value
-The number of bytes in the string `<str>`.
+Returns INT type, representing the byte length of the string.
-## Example
+Special cases:
+- If parameter is NULL, returns NULL
+- Empty string returns 0
+- Result is the number of bytes in UTF-8 encoding
+## Examples
+
+1. ASCII characters (byte count = character count)
```sql
-SELECT LENGTH("abc"),length("中国")
+SELECT LENGTH('abc'), CHAR_LENGTH('abc');
```
-
```text
-+---------------+------------------+
-| length('abc') | length('中国') |
-+---------------+------------------+
-| 3 | 6 |
-+---------------+------------------+
++---------------+--------------------+
+| LENGTH('abc') | CHAR_LENGTH('abc') |
++---------------+--------------------+
+| 3 | 3 |
++---------------+--------------------+
```
+2. Chinese characters (byte count > character count)
```sql
-SELECT length(x'34AAA'), length(x'34AAA');
+SELECT LENGTH('中国'), CHAR_LENGTH('中国');
+```
+```text
++------------------+---------------------+
+| LENGTH('中国') | CHAR_LENGTH('中国') |
++------------------+---------------------+
+| 6 | 2 |
++------------------+---------------------+
```
+3. NULL value handling
+```sql
+SELECT LENGTH(NULL);
+```
```text
-+------------------+------------------+
-| length(x'34AAA') | length(x'34AAA') |
-+------------------+------------------+
-| 3 | 3 |
-+------------------+------------------+
++--------------+
+| LENGTH(NULL) |
++--------------+
+| NULL |
++--------------+
```
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/locate.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/locate.md
index 42934b5f720..cacbd741a6d 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/locate.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/locate.md
@@ -7,36 +7,74 @@
## Description
-Returns the position of substr in str (counting from 1). If the third parameter pos is specified, the position of substr is searched from the string starting with the pos subscript. If not found, 0 is returned
+The LOCATE function returns the position of the first occurrence of substring substr in string str (counting starts from 1). If an optional third parameter pos is specified, the search starts from the specified position in string str. This is a MySQL-compatible function commonly used for string matching and position finding.
## Syntax
```sql
-LOCATE ( <substr> , <str> [, <pos> ] )
+LOCATE(<substr>, <str> [, <pos>])
```
## Parameters
| Parameter | Description |
-|-----------|-----------------|
-| `substr` | The substring to be searched |
-| `str` | The string to be searched |
-| `pos` | If this parameter is specified, the position of substr is searched from the string starting with the pos subscript|
+|----------|-----------------|
+| `<substr>` | The target substring to find. Type: VARCHAR |
+| `<str>` | The source string to search in. Type: VARCHAR |
+| `<pos>` | Optional parameter, the starting position for the search (counting from 1). Type: INT |
-## Return value
+## Return Value
-The position of substr in str (counting from 1)
+Returns INT type, representing the position of the first occurrence of substr in str (counting from 1).
-## Example
+Search rules:
+- Position counting starts from 1 (not from 0)
+- Returns the position of the first match
+- If pos is specified, search starts from that position, but the returned position is still the absolute position relative to the string beginning
+- Search is case-sensitive
+Special cases:
+- If no match is found, returns 0
+- If any parameter is NULL, returns NULL
+- If substr is an empty string, returns 1 (or the value of pos if pos is specified and pos > 1)
+- If str is empty but substr is not, returns 0
+- If pos is less than 1, returns 0
+- If pos is greater than the length of str, returns 0
+
+## Examples
+
+1. Basic search
```sql
-SELECT LOCATE('bar', 'foobarbar'),LOCATE('xbar', 'foobar'),LOCATE('bar', 'foobarbar', 5)
+SELECT LOCATE('bar', 'foobarbar'), LOCATE('xbar', 'foobar'), LOCATE('bar', 'foobarbar', 5);
```
-
```text
+----------------------------+--------------------------+-------------------------------+
-| locate('bar', 'foobarbar') | locate('xbar', 'foobar') | locate('bar', 'foobarbar', 5) |
+| LOCATE('bar', 'foobarbar') | LOCATE('xbar', 'foobar') | LOCATE('bar', 'foobarbar', 5) |
+----------------------------+--------------------------+-------------------------------+
| 4 | 0 | 7 |
+----------------------------+--------------------------+-------------------------------+
+```
+
+2. Finding first character
+```sql
+SELECT LOCATE('f', 'foobar'), LOCATE('r', 'foobar');
+```
+```text
++-----------------------+-----------------------+
+| LOCATE('f', 'foobar') | LOCATE('r', 'foobar') |
++-----------------------+-----------------------+
+| 1 | 6 |
++-----------------------+-----------------------+
+```
+
+3. No match found
+```sql
+SELECT LOCATE('xyz', 'foobar'), LOCATE('FOO', 'foobar');
+```
+```text
++-------------------------+-------------------------+
+| LOCATE('xyz', 'foobar') | LOCATE('FOO', 'foobar') |
++-------------------------+-------------------------+
+| 0 | 0 |
++-------------------------+-------------------------+
```
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/lpad.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/lpad.md
index 5e91dda1107..0765a4bb35c 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/lpad.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/lpad.md
@@ -7,46 +7,72 @@
## Description
-Returns a string of length len (starting from the first letter) in str.
-
-If len is greater than the length of str, pad characters are added to the front of str until the length of the string reaches len.
-
-If len is less than the length of str, this function is equivalent to truncating the str string and returning only a string of length len. len refers to the character length rather than the byte length.
-
-Special cases:
-
-- In addition to containing NULL values, if pad is empty, the return value is an empty string.
+The LPAD function (Left Padding) pads a string on the left side with specified characters until it reaches the specified length. If the target length is less than the original string length, the string is truncated.
## Syntax
```sql
-LPAD ( <str> , <len> , <pad>)
+LPAD(<str>, <len>, <pad>)
```
## Parameters
-| Parameters | Description |
-|------------|------------------------------|
-| `<str>` | The string to be padded |
-| `<len>` | The length of the string to be padded, which refers to the length of characters rather than bytes |
-| `<pad>` | The string to be padded on the left of the original string |
+| Parameter | Description |
+|---------|------------------------------|
+| `<str>` | The source string to be padded. Type: VARCHAR |
+| `<len>` | Target string character length (not byte length). Type: INT |
+| `<pad>` | The string used for padding. Type: VARCHAR |
+
+## Return Value
-## Return value
+Returns VARCHAR type, representing the padded or truncated string.
-The padded string. Special cases:
+Padding rules:
+- If len > original string length: Repeatedly pad on the left with pad string until total length reaches len
+- If len = original string length: Return original string
+- If len < original string length: Truncate string, return only first len characters
+- Calculated by character length, supports UTF-8 multi-byte characters
+
+Special cases:
+- If any parameter is NULL, returns NULL
+- If pad is empty string and len > str length, returns empty string
+- If len is 0, returns empty string
+- If len is negative, returns NULL
-- If pad is empty, the return value is an empty string, except when it contains NULL values.
+## Examples
-## Example
+1. Basic left padding
+```sql
+SELECT LPAD('hi', 5, 'xy'), LPAD('hello', 8, '*');
+```
+```text
++---------------------+-----------------------+
+| LPAD('hi', 5, 'xy') | LPAD('hello', 8, '*') |
++---------------------+-----------------------+
+| xyxhi | ***hello |
++---------------------+-----------------------+
+```
+2. String truncation
```sql
-SELECT LPAD("hi", 5, "xy"),LPAD("hi", 1, "xy"),LPAD("", 0, "")
+SELECT LPAD('hi', 1, 'xy'), LPAD('hello world', 5, 'x');
+```
+```text
++---------------------+------------------------------+
+| LPAD('hi', 1, 'xy') | LPAD('hello world', 5, 'x') |
++---------------------+------------------------------+
+| h | hello |
++---------------------+------------------------------+
```
+3. NULL value handling
+```sql
+SELECT LPAD(NULL, 5, 'x'), LPAD('hi', NULL, 'x'), LPAD('hi', 5, NULL);
+```
```text
-+---------------------+---------------------+-----------------+
-| lpad('hi', 5, 'xy') | lpad('hi', 1, 'xy') | lpad('', 0, '') |
-+---------------------+---------------------+-----------------+
-| xyxhi | h | |
-+---------------------+---------------------+-----------------+
++---------------------+------------------------+----------------------+
+| LPAD(NULL, 5, 'x') | LPAD('hi', NULL, 'x') | LPAD('hi', 5, NULL) |
++---------------------+------------------------+----------------------+
+| NULL | NULL | NULL |
++---------------------+------------------------+----------------------+
```
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/ltrim.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/ltrim.md
index 3dcdcbacfda..69a76ba30ab 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/ltrim.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/ltrim.md
@@ -7,49 +7,71 @@
## Description
-The LTRIM function is used to remove consecutive spaces or specified characters from the left side (leading) of a string.
+The LTRIM function removes consecutive occurrences of spaces or specified character sets from the left side (beginning) of a string. This function scans from the left end of the string and removes all consecutive target characters until it encounters a character not in the target character set.
## Syntax
```sql
-LTRIM( <str> [, <trim_chars> ] )
+LTRIM(<str> [, <trim_chars>])
```
## Parameters
| Parameter | Description |
|----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `<str>` | String that need to be trimmed |
-| `<trim_chars>` | Optional Parameter. If this parameter is provided, the LTRIM function will remove all characters from the `<trim_chars>` that appear on the left side of `<str>`. If this parameter is not provided, the LTRIM function will only remove the space character to the left of `'<str>'`. |
+| `<str>` | The source string to be left-trimmed. Type: VARCHAR |
+| `<trim_chars>` | Optional parameter, specifies the set of characters to remove. If not provided, defaults to removing space characters. Type: VARCHAR |
## Return Value
-Returns a string with leading spaces or `<trim_chars>` removed. Special cases:
+Returns VARCHAR type, representing the string after removing specified characters from the left side.
-- If any Parameter is NULL, NULL will be returned.
+Trimming rules:
+- Only removes characters from the left side (beginning) of the string
+- Removes all consecutive characters that appear in trim_chars
+- Stops removing once a character not in trim_chars is encountered
+- If trim_chars is not specified, defaults to removing space characters (including spaces, tabs, newlines, etc.)
+
+Special cases:
+- If any parameter is NULL, returns NULL
+- If str is empty string, returns empty string
+- If trim_chars is empty string, returns original string
+- If entire string consists of characters in trim_chars, returns empty string
## Examples
+1. Remove left spaces
```sql
-SELECT ltrim(' ab d') str;
+SELECT LTRIM(' ab d');
```
-
```text
-+------+
-| str |
-+------+
-| ab d |
-+------+
++-------------------+
+| LTRIM(' ab d') |
++-------------------+
+| ab d |
++-------------------+
```
+2. Remove specified characters
```sql
-SELECT ltrim('ababccaab','ab') str;
+SELECT LTRIM('ababccaab', 'ab');
+```
+```text
++----------------------------+
+| LTRIM('ababccaab', 'ab') |
++----------------------------+
+| ccaab |
++----------------------------+
```
+3. NULL value handling
+```sql
+SELECT LTRIM(NULL), LTRIM('test', NULL);
+```
```text
-+-------+
-| str |
-+-------+
-| ccaab |
-+-------+
++-------------+---------------------+
+| LTRIM(NULL) | LTRIM('test', NULL) |
++-------------+---------------------+
+| NULL | NULL |
++-------------+---------------------+
```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/make-set.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/make-set.md
index 371c8e7258e..20df74d6c6f 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/make-set.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/make-set.md
@@ -7,94 +7,108 @@
## Description
-MAKE_SET returns a comma-separated set of strings.
-The set is composed of the strings whose corresponding bits in `bit` are 1: str1 corresponds to bit 0, str2 to bit 1, and so on. NULL values in the strs are not included in the set.
+The MAKE_SET function selects and combines strings from multiple string parameters based on a bitmask (bit). Returns a comma-separated string set containing all strings whose corresponding bit is 1.
-Aligns with the behavior of [MAKE_SET](https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#function-make-set) in MySQL.
+Behavior aligns with [MAKE_SET](https://dev.mysql.com/doc/refman/8.4/en/string-functions.html#function-make-set) in MySQL.
## Syntax
```sql
-MAKE_SET(<bit>, <str1>, <str2>...)
+MAKE_SET(<bit>, <str1>[, <str2>, ...])
```
-## Arguments
+## Parameters
-| Argument | Description |
-|----------------|--------------------------------------------------------------------------|
-| `<bit>` | The provided integer bit value, indicating which positions' strings to include. Size limit: 2^64 ~ 2^64-1(BIGINT) |
-| `<strs>` | The strings to be combined |
+| Parameter | Description |
+| -------- | ----------------------------------------- |
+| `<bit>` | Bitmask value, binary bits indicate which strings to select. Type: BIGINT |
+| `<str1>`, `<str2>`, ... | String parameters to be combined (variable arguments). Type: VARCHAR |
## Return Value
-Return a string type, which is a collection of strings formed by the bits where the corresponding bit is 1, and the strings in the collection are separated by ','.
+Returns VARCHAR type, a comma-separated string set.
-If a str corresponding to a bit set to 1 is NULL or does not exist, that position is skipped.
+Special cases:
+- If `<bit>` is NULL, returns NULL
+- If a string corresponding to a bit set to 1 is NULL, skip that string
+- If corresponding bit exceeds parameter range, ignore that bit
+- Binary bits count from right to left, bit 0 corresponds to the first string parameter
+- When `<bit>` is 0, returns empty string
-Returns NULL when `bit` is NULL.
-
-## Example
+## Examples
+1. Basic usage: bit = 3 (binary 011, selects bit 0 and bit 1)
```sql
-CREATE TABLE test_make_set (
- id int,
- bit_num BIGINT,
- vc1 VARCHAR(50),
- vc2 VARCHAR(50),
- vc3 VARCHAR(50)
-)
-DUPLICATE KEY(id)
-DISTRIBUTED BY HASH(id) BUCKETS 1
-PROPERTIES ( 'replication_num' = '1' );
-
-INSERT INTO test_make_set (id, bit_num, vc1, vc2, vc3) VALUES
-(1, 1, 'apple', 'orange', NULL),
-(2, 2, 'red', 'blue', NULL),
-(3, 3, 'dog', 'cat', 'bird'),
-(4, 4, 'small', 'medium', 'large'),
-(5, 5, NULL, 'warm', 'hot'),
-(6, 6, 'monday', 'tuesday', 'wednesday'),
-(7, 7, 'one', 'two', 'three'),
-(8, 0, 'hello', 'world', NULL),
-(9, -2, 'test1', 'test2', 'test3'),
-(10, -3, '汽车', '自行车', '火车'),
-(11, NULL, 'a', 'b', 'c'),
-(12, 7, NULL, NULL, NULL),
-(13, 3, '', 'should after ,', 'useless');
+SELECT make_set(3, 'dog', 'cat', 'bird');
+```
+```text
++-----------------------------------+
+| make_set(3, 'dog', 'cat', 'bird') |
++-----------------------------------+
+| dog,cat |
++-----------------------------------+
```
+2. Skip NULL values: bit = 5 (binary 101, selects bit 0 and bit 2)
```sql
-SELECT id, MAKE_SET(bit_num, vc1, vc2, vc3) FROM test_make_set;
+SELECT make_set(5, NULL, 'warm', 'hot');
```
```text
-+------+----------------------------------+
-| id | MAKE_SET(bit_num, vc1, vc2, vc3) |
-+------+----------------------------------+
-| 1 | apple |
-| 2 | blue |
-| 3 | dog,cat |
-| 4 | large |
-| 5 | hot |
-| 6 | tuesday,wednesday |
-| 7 | one,two,three |
-| 8 | |
-| 9 | test2,test3 |
-| 10 | 汽车,火车 |
-| 11 | NULL |
-| 12 | |
-| 13 | ,should after , |
-+------+----------------------------------+
++---------------------------------+
+| make_set(5, NULL, 'warm', 'hot') |
++---------------------------------+
+| hot |
++---------------------------------+
```
-Explanation:
-1. When id == 3, its bit_num == 3, which is represented as 011 in binary. The 0th and 1st bits are 1, representing the parameters str1 and str2 respectively. Therefore, str1 and str2 are used to construct the final result, with str1 and str2 separated by a comma. The final answer can be represented as `${str1},${str2}`, which is `dog,cat`.
+3. bit is 0: Select no strings
+```sql
+SELECT make_set(0, 'hello', 'world');
+```
+```text
++--------------------------------+
+| make_set(0, 'hello', 'world') |
++--------------------------------+
+| |
++--------------------------------+
+```
-2. When id == 5, its bit_num == 5, which is represented as 101 in binary. The 0th and 2nd bits are 1, representing the parameters str1 and str3 respectively. Since str1 is NULL and does not participate in the final result, the final result can be represented as `${str3}`, which is `hot`.
+4. NULL value handling
+```sql
+SELECT make_set(NULL, 'a', 'b', 'c');
+```
+```text
++-------------------------------+
+| make_set(NULL, 'a', 'b', 'c') |
++-------------------------------+
+| NULL |
++-------------------------------+
+```
-3. When id == 13, its bit_num == 3, which is represented as 011 in binary. Therefore, str1 and str2 are used to construct the final result, represented as `${str1},${str2}`. Since str1 is an empty string, the final result can be simplified to `,${str2}` which is `,should after ,`.
+5. Bit exceeds parameter range: bit = 15 (binary 1111, selects 4 bits, but only 2 parameters)
+```sql
+SELECT make_set(15, 'first', 'second');
+```
+```text
++-------------------------------------+
+| make_set(15, 'first', 'second') |
++-------------------------------------+
+| first,second |
++-------------------------------------+
+```
-The `bit` parameter is constrained to integers from 2^64 to 2^64-1 (BIGINT), and out-of-bound behavior is reported as follows:
+6. UTF-8 special character support
+```sql
+SELECT make_set(7, 'ṭṛì', 'ḍḍumai', 'test');
+```
```text
-mysql> SELECT MAKE_SET(184467440737095516156, 'a', 'b', 'c');
-ERROR 1105 (HY000): errCode = 2, detailMessage = Can not find the compatibility function signature: make_set(LARGEINT, VARCHAR(1), VARCHAR(1), VARCHAR(1))
-```
\ No newline at end of file
++------------------------------------------+
+| make_set(7, 'ṭṛì', 'ḍḍumai', 'test') |
++------------------------------------------+
+| ṭṛì,ḍḍumai,test |
++------------------------------------------+
+```
+
+### Keywords
+
+ MAKE_SET
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/mask-first-n.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/mask-first-n.md
index 1b28811e5b7..17d3b160eca 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/mask-first-n.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/mask-first-n.md
@@ -7,59 +7,155 @@
## Description
-The MASK_FIRST_N function is mainly used to mask the first N bytes of data to protect sensitive information, and is commonly used in data anonymization scenarios. Its behavior is to replace a uppercase letter with `X`, a lowercase letter with `x`, and a number with `n` in the first N bytes.
+The MASK_FIRST_N function is used to mask the first N bytes of a string. It replaces uppercase letters with `X`, lowercase letters with `x`, and digits with `n` in the first N bytes.
## Syntax
```sql
-MASK_FIRST_N( <str> [, <n> ])
+MASK_FIRST_N(<str>[, <n>])
```
## Parameters
-| Parameter | Description |
-|-----------|--------------------------------------------------------------------------------------------------------|
-| `<str>` | String that need to be masked |
-| `<n>` | Optional Parameter, limit data masking to only the first N bytes, default to masking the entire string |
+| Parameter | Description |
+| ------- | ----------------------------------------- |
+| `<str>` | The string to be masked. Type: VARCHAR |
+| `<n>` | The number of first N bytes to mask (optional, defaults to entire string). Type: INT |
## Return Value
-Returns a string after masking uppercase character, lowercase character and lnumeric character in first N bytes. Special cases:
+Returns VARCHAR type, the string with the first N bytes masked.
-- If any Parameter is NULL, NULL will be returned.
-- Non-alphabetic and non-numeric characters will do not masking
-- Only ASCII letters are supported for replacement, non-ASCII letters (such as accented Latin letters) will be preserved as is
+Special cases:
+- If any parameter is NULL, returns NULL
+- Non-alphanumeric characters remain unchanged
+- If `<n>` is greater than string length, masks the entire string
## Examples
+1. Basic usage: mask first 4 bytes
```sql
-select mask_first_n("1234-5678-8765-4321", 4);
+SELECT mask_first_n('1234-5678', 4);
+```
+```text
++------------------------------+
+| mask_first_n('1234-5678', 4) |
++------------------------------+
+| nnnn-5678 |
++------------------------------+
+```
+
+2. Without specifying n (masks entire string)
+```sql
+SELECT mask_first_n('abc123');
+```
+```text
++-----------------------+
+| mask_first_n('abc123') |
++-----------------------+
+| xxxnnn |
++-----------------------+
+```
+
+3. n exceeds string length
+```sql
+SELECT mask_first_n('Hello', 100);
+```
+```text
++----------------------------+
+| mask_first_n('Hello', 100) |
++----------------------------+
+| Xxxxx |
++----------------------------+
+```
+
+4. NULL value handling
+```sql
+SELECT mask_first_n(NULL, 5);
+```
+```text
++-----------------------+
+| mask_first_n(NULL, 5) |
++-----------------------+
+| NULL |
++-----------------------+
+```
+
+5. n is 0 (masks no characters)
+```sql
+SELECT mask_first_n('Hello123', 0);
+```
+```text
++-----------------------------+
+| mask_first_n('Hello123', 0) |
++-----------------------------+
+| Hello123 |
++-----------------------------+
+```
+
+6. n greater than string length (masks entire string)
+```sql
+SELECT mask_first_n('Test', 100);
+```
+```text
++---------------------------+
+| mask_first_n('Test', 100) |
++---------------------------+
+| Xxxx |
++---------------------------+
```
+7. Mask email address prefix
+```sql
+SELECT mask_first_n('user@example.com', 6);
+```
```text
-+----------------------------------------+
-| mask_first_n('1234-5678-8765-4321', 4) |
-+----------------------------------------+
-| nnnn-5678-8765-4321 |
-+----------------------------------------+
++-------------------------------------+
+| mask_first_n('user@example.com', 6) |
++-------------------------------------+
+| xxxx@xxample.com |
++-------------------------------------+
```
+8. Mask first 3 digits of phone number
```sql
-select mask_first_n("1234-5678-8765-4321", null);
+SELECT mask_first_n('13812345678', 3);
+```
+```text
++--------------------------------+
+| mask_first_n('13812345678', 3) |
++--------------------------------+
+| nnn12345678 |
++--------------------------------+
```
+9. Mixed letters, digits and special characters
+```sql
+SELECT mask_first_n('Abc-123-XYZ', 7);
+```
```text
-+-------------------------------------------+
-| mask_first_n('1234-5678-8765-4321', NULL) |
-+-------------------------------------------+
-| NULL |
-+-------------------------------------------+
++---------------------------------+
+| mask_first_n('Abc-123-XYZ', 7) |
++---------------------------------+
+| Xxx-nnn-XYZ |
++---------------------------------+
```
+10. UTF-8 character handling (masks by byte)
```sql
-select mask_first_n('eeeéèêëìí1234');
+SELECT mask_first_n('ṭṛWorld123', 7);
+```
+```text
++-----------------------------------+
+| mask_first_n('ṭṛWorld123', 7) |
++-----------------------------------+
+| ṭṛXorld123 |
++-----------------------------------+
```
+```sql
+SELECT mask_first_n('eeeéèêëìí1234');
+```
```text
+-------------------------------------+
| mask_first_n('eeeéèêëìí1234') |
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/mask-last-n.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/mask-last-n.md
index 890b3b823d3..94390a1aa3e 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/mask-last-n.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/mask-last-n.md
@@ -7,59 +7,155 @@
## Description
-The MASK_LAST_N function is mainly used to mask the last N bytes of data to protect sensitive information, and is commonly used in data anonymization scenarios. Its behavior is to replace a uppercase letter with `X`, a lowercase letter with `x`, and a number with `n` in the first N bytes.
+The MASK_LAST_N function is used to mask the last N bytes of a string. It replaces uppercase letters with `X`, lowercase letters with `x`, and digits with `n` in the last N bytes.
## Syntax
```sql
-MASK_LAST_N( <str> [, <n> ])
+MASK_LAST_N(<str>[, <n>])
```
## Parameters
-| Parameter | Description |
-|-----------|-------------------------------------------------------------------------------------------------------|
-| `<str>` | String that need to be masked |
-| `<n>` | Optional Parameter, limit data masking to only the last N bytes, default to masking the entire string |
+| Parameter | Description |
+| ------- | ----------------------------------------- |
+| `<str>` | The string to be masked. Type: VARCHAR |
+| `<n>` | The number of last N bytes to mask (optional, defaults to entire string). Type: INT |
## Return Value
-Returns a string after masking uppercase character, lowercase character and lnumeric character in last N bytes. Special cases:
+Returns VARCHAR type, the string with the last N bytes masked.
-- If any Parameter is NULL, NULL will be returned.
-- Non-alphabetic and non-numeric characters will do not masking
-- Only ASCII letters are supported for replacement, non-ASCII letters (such as accented Latin letters) will be preserved as is
+Special cases:
+- If any parameter is NULL, returns NULL
+- Non-alphanumeric characters remain unchanged
+- If `<n>` is greater than string length, masks the entire string
## Examples
+1. Basic usage: mask last 4 bytes
```sql
-select mask_last_n("1234-5678-8765-4321", 4);
+SELECT mask_last_n('1234-5678', 4);
+```
+```text
++-----------------------------+
+| mask_last_n('1234-5678', 4) |
++-----------------------------+
+| 1234-nnnn |
++-----------------------------+
```
+2. Without specifying n (masks entire string)
+```sql
+SELECT mask_last_n('abc123');
+```
```text
-+---------------------------------------+
-| mask_last_n('1234-5678-8765-4321', 4) |
-+---------------------------------------+
-| 1234-5678-8765-nnnn |
-+---------------------------------------+
++----------------------+
+| mask_last_n('abc123') |
++----------------------+
+| xxxnnn |
++----------------------+
```
+3. n exceeds string length
```sql
-select mask_last_n("1234-5678-8765-4321", null);
+SELECT mask_last_n('Hello', 100);
+```
+```text
++---------------------------+
+| mask_last_n('Hello', 100) |
++---------------------------+
+| Xxxxx |
++---------------------------+
```
+4. NULL value handling
+```sql
+SELECT mask_last_n(NULL, 5);
+```
```text
-+-------------------------------------------+
-| mask_last_n('1234-5678-8765-4321', NULL) |
-+-------------------------------------------+
-| NULL |
-+-------------------------------------------+
++----------------------+
+| mask_last_n(NULL, 5) |
++----------------------+
+| NULL |
++----------------------+
```
+5. n is 0 (masks no characters)
```sql
-select mask_last_n('eeeéèêëìí1234');
+SELECT mask_last_n('Hello123', 0);
+```
+```text
++----------------------------+
+| mask_last_n('Hello123', 0) |
++----------------------------+
+| Hello123 |
++----------------------------+
```
+6. n greater than string length (masks entire string)
+```sql
+SELECT mask_last_n('Test', 100);
+```
+```text
++--------------------------+
+| mask_last_n('Test', 100) |
++--------------------------+
+| Xxxx |
++--------------------------+
+```
+
+7. Mask email domain part
+```sql
+SELECT mask_last_n('user@example.com', 11);
+```
+```text
++-------------------------------------+
+| mask_last_n('user@example.com', 11) |
++-------------------------------------+
+| user@xxxxxxx.xxx |
++-------------------------------------+
+```
+
+8. Mask last 4 digits of phone number
+```sql
+SELECT mask_last_n('13812345678', 4);
+```
+```text
++-------------------------------+
+| mask_last_n('13812345678', 4) |
++-------------------------------+
+| 1381234nnnn |
++-------------------------------+
+```
+
+9. Mixed letters, digits and special characters
+```sql
+SELECT mask_last_n('ABC-123-xyz', 7);
+```
+```text
++--------------------------------+
+| mask_last_n('ABC-123-xyz', 7) |
++--------------------------------+
+| ABC-nnn-xxx |
++--------------------------------+
+```
+
+10. UTF-8 character handling (masks by byte)
+```sql
+SELECT mask_last_n('Helloṭṛ123', 9);
+```
+```text
++--------------------------------+
+| mask_last_n('Hello你好123', 9) |
++--------------------------------+
+| Hello你好nnn |
++--------------------------------+
+```
+
+```sql
+SELECT mask_last_n('eeeéèêëìí1234');
+```
```text
+------------------------------------+
| mask_last_n('eeeéèêëìí1234') |
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/mask.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/mask.md
index 4aed8a5d46b..64747bf4476 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/mask.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/mask.md
@@ -7,49 +7,74 @@
## Description
-The MASK function is to shield data to protect sensitive information, and it is commonly used in data anonymization scenarios. Its default behavior is to convert a uppercase letter in the input string to `X`, a lowercase letter to `x`, and a number to `n`.
+The MASK function is used to mask data to protect sensitive information. The default behavior is to convert uppercase letters to `X`, lowercase letters to `x`, and digits to `n`.
## Syntax
```sql
-MASK(<str> [, <upper> [, <lower> [, <number> ]]])
+MASK(<str>[, <upper>[, <lower>[, <number>]]])
```
## Parameters
-| Parameter | Description |
-|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `<str>` | String that need to be masked |
-| `<upper>` | Optional Parameter, replaces uppercase character to `X` by default. If a sequence of characters are input, the first character will be taken, and if non ASCII characters are input, the first byte will be taken |
-| `<lower>` | Optional Parameter, replaces lowercase character to `x` by default. If a sequence of characters are input, the first character will be taken, and if non ASCII characters are input, the first byte will be taken |
-| `<number>` | Optional Parameter, replaces numeric character to `n` by default. If a sequence of characters are input, the first character will be taken, and if non ASCII characters are input, the first byte will be taken |
+| Parameter | Description |
+| ---------- | ----------------------------------------- |
+| `<str>` | The string to be masked. Type: VARCHAR |
+| `<upper>` | Character to replace uppercase letters with, default is `X` (optional). Type: VARCHAR |
+| `<lower>` | Character to replace lowercase letters with, default is `x` (optional). Type: VARCHAR |
+| `<number>` | Character to replace digits with, default is `n` (optional). Type: VARCHAR |
## Return Value
-Returns a string after masking uppercase character, lowercase character and lnumeric character. Special cases:
+Returns VARCHAR type, the string with letters and digits replaced.
-- If any Parameter is NULL, NULL will be returned.
-- Non-alphabetic and non-numeric characters will do not masking
-- Only ASCII letters are supported for replacement, non-ASCII letters (such as accented Latin letters) will be preserved as is
+Special cases:
+- If any parameter is NULL, returns NULL
+- Non-alphanumeric characters remain unchanged
+- If replacement character parameters contain multiple characters, only the first character is used
## Examples
+1. Basic usage: default replacement rules
```sql
-select mask('abc123EFG');
+SELECT mask('abc123XYZ');
```
-
```text
+-------------------+
-| mask('abc123EFG') |
+| mask('abc123XYZ') |
+-------------------+
| xxxnnnXXX |
+-------------------+
```
+2. Custom replacement characters
```sql
-select mask(null);
+SELECT mask('abc123XYZ', '*', '#', '$');
+```
+```text
++----------------------------------+
+| mask('abc123XYZ', '*', '#', '$') |
++----------------------------------+
+| ###$$$*** |
++----------------------------------+
+```
+
+3. Special characters remain unchanged
+```sql
+SELECT mask('Hello-123!');
+```
+```text
++--------------------+
+| mask('Hello-123!') |
++--------------------+
+| Xxxxx-nnn! |
++--------------------+
```
+4. NULL value handling
+```sql
+SELECT mask(NULL);
+```
```text
+------------+
| mask(NULL) |
@@ -58,22 +83,81 @@ select mask(null);
+------------+
```
+5. Digits-only string
```sql
-select mask('abc123EFG', '*', '#', '$');
+SELECT mask('1234567890');
+```
+```text
++--------------------+
+| mask('1234567890') |
++--------------------+
+| nnnnnnnnnn |
++--------------------+
```
+6. Letters-only string
+```sql
+SELECT mask('AbCdEfGh');
+```
```text
-+----------------------------------+
-| mask('abc123EFG', '*', '#', '$') |
-+----------------------------------+
-| ###$$$*** |
-+----------------------------------+
++------------------+
+| mask('AbCdEfGh') |
++------------------+
+| XxXxXxXx |
++------------------+
```
+7. Empty string handling
```sql
-select mask('eeeéèêëìí1234');
+SELECT mask('');
+```
+```text
++----------+
+| mask('') |
++----------+
+| |
++----------+
+```
+
+8. Single character replacement (takes first character from multiple)
+```sql
+SELECT mask('Test123', 'ABC', 'xyz', '999');
+```
+```text
++--------------------------------------+
+| mask('Test123', 'ABC', 'xyz', '999') |
++--------------------------------------+
+| Xxxx999 |
++--------------------------------------+
+```
+
+9. Mask credit card number
+```sql
+SELECT mask('1234-5678-9012-3456');
+```
+```text
++-----------------------------+
+| mask('1234-5678-9012-3456') |
++-----------------------------+
+| nnnn-nnnn-nnnn-nnnn |
++-----------------------------+
```
+10. Mask email address
+```sql
+SELECT mask('user@example.com');
+```
+```text
++--------------------------+
+| mask('user@example.com') |
++--------------------------+
+| xxxx@xxxxxxx.xxx |
++--------------------------+
+```
+
+```sql
+SELECT mask('eeeéèêëìí1234');
+```
```text
+-----------------------------+
| mask('eeeéèêëìí1234') |
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/multi-search-all-positions.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/multi-search-all-positions.md
index ad2e4ac9a08..1039fadf089 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/multi-search-all-positions.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/multi-search-all-positions.md
@@ -5,31 +5,96 @@
}
---
-## multi_search_all_positions
-### Description
-#### Syntax
+## Description
-`ARRAY<INT> multi_search_all_positions(VARCHAR haystack, ARRAY<VARCHAR> needles)`
+The MULTI_SEARCH_ALL_POSITIONS function searches for multiple substrings in a string in batch. Returns an array containing the position of the first occurrence of each substring. The search is case-sensitive.
-Returns an `ARRAY` where the `i`-th element is the position of the `i`-th element in `needles`(i.e. `needle`)'s **first** occurrence in the string `haystack`. Positions are counted from 1, with 0 meaning the element was not found. **Case-sensitive**.
+## Syntax
-### example
+```sql
+MULTI_SEARCH_ALL_POSITIONS(<haystack>, <needles>)
+```
+
+## Parameters
+
+| Parameter | Description |
+| ------------ | ----------------------------------------- |
+| `<haystack>` | The target string to search in. Type: VARCHAR |
+| `<needles>` | Array containing multiple substrings to search for. Type: ARRAY<VARCHAR> |
+
+## Return Value
+
+Returns ARRAY<INT> type, where the i-th element in the array represents the position of the first occurrence of the i-th substring in `<needles>` within `<haystack>`.
+
+Special cases:
+- Position counting starts from 1
+- If substring is not found, the corresponding position returns 0
+- Search is case-sensitive
+- If `<haystack>` or `<needles>` is NULL, returns NULL
+- Returns byte position, not the n-th character position
+
+## Examples
+
+1. Basic usage: Search for multiple substrings
+```sql
+SELECT multi_search_all_positions('Hello, World!', ['Hello', 'World']);
+```
+```text
++----------------------------------------------------------+
+| multi_search_all_positions('Hello, World!', ['Hello', 'World']) |
++----------------------------------------------------------+
+| [1, 8] |
++----------------------------------------------------------+
+```
+2. Case-sensitive: Lowercase not found
+```sql
+SELECT multi_search_all_positions('Hello, World!', ['hello', '!', 'world']);
```
-mysql> select multi_search_all_positions('Hello, World!', ['hello', '!', 'world']);
+```text
+----------------------------------------------------------------------+
| multi_search_all_positions('Hello, World!', ['hello', '!', 'world']) |
+----------------------------------------------------------------------+
-| [0,13,0] |
+| [0, 13, 0] |
+----------------------------------------------------------------------+
+```
-select multi_search_all_positions("Hello, World!", ['hello', '!', 'world', 'Hello', 'World']);
-+---------------------------------------------------------------------------------------------+
-| multi_search_all_positions('Hello, World!', ARRAY('hello', '!', 'world', 'Hello', 'World')) |
-+---------------------------------------------------------------------------------------------+
-| [0, 13, 0, 1, 8] |
-+---------------------------------------------------------------------------------------------+
+3. Mixed search: Partially found
+```sql
+SELECT multi_search_all_positions('Hello, World!', ['Hello', '!', 'xyz']);
+```
+```text
++--------------------------------------------------------------------+
+| multi_search_all_positions('Hello, World!', ['Hello', '!', 'xyz']) |
++--------------------------------------------------------------------+
+| [1, 13, 0] |
++--------------------------------------------------------------------+
+```
+
+4. Empty array
+```sql
+SELECT multi_search_all_positions('Hello', []);
+```
+```text
++------------------------------------------+
+| multi_search_all_positions('Hello', []) |
++------------------------------------------+
+| [] |
++------------------------------------------+
```
-### keywords
+5. UTF-8 special character support
+```sql
+SELECT multi_search_all_positions('ṭṛì ḍḍumai Hello', ['ṭṛì', 'Hello', 'test']);
+```
+```text
++----------------------------------------------------------------------------------------+
+| multi_search_all_positions('ṭṛì ḍḍumai Hello', ['ṭṛì', 'Hello', 'test']) |
++----------------------------------------------------------------------------------------+
+| [1, 21, 0] |
++----------------------------------------------------------------------------------------+
+```
+
+### Keywords
+
MULTI_SEARCH,SEARCH,POSITIONS
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/ngram-search.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/ngram-search.md
index 0cd131c52f9..96cd3eeb559 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/ngram-search.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/ngram-search.md
@@ -7,42 +7,86 @@
## Description
-Calculate the N-gram similarity between `text` and `pattern`. The similarity ranges from 0 to 1, where a higher similarity indicates greater similarity between the two strings.
+The NGRAM_SEARCH function calculates the N-gram similarity between two strings. The similarity ranges from 0 to 1, where higher values indicate more similar strings.
-Both `pattern` and `gram_num` must be constants. If the length of either `text` or `pattern` is less than `gram_num`, return 0.
+N-gram decomposes a string into a set of consecutive N characters. The similarity calculation formula is: `2 * |intersection| / (|set1| + |set2|)`
-N-gram similarity is a method for calculating text similarity based on N-grams. An N-gram is a set of continuous N characters or words extracted from a text string. For example, for the string "text" with N=2 (bigram), the bigrams are: {"te", "ex", "xt"}.
+Only ASCII characters are supported.
-The N-gram similarity is calculated as:
+## Syntax
-2 * |Intersection| / (|text set| + |pattern set|)
+```sql
+NGRAM_SEARCH(<text>, <pattern>, <gram_num>)
+```
-where |text set| and |pattern set| are the N-grams of `text` and `pattern`, and `Intersection` is the intersection of the two sets.
+## Parameters
-Note that, by definition, a similarity of 1 does not necessarily mean the two strings are identical.
+| Parameter | Description |
+| ------------ | ----------------------------------------- |
+| `<text>` | The text string to compare. Type: VARCHAR |
+| `<pattern>` | Pattern string (must be constant). Type: VARCHAR |
+| `<gram_num>` | The N value for N-gram (must be constant). Type: INT |
-Only supports ASCII encoding.
+## Return Value
-## Syntax
+Returns DOUBLE type, the N-gram similarity between the two strings (between 0 and 1).
-`DOUBLE ngram_search(VARCHAR text,VARCHAR pattern,INT gram_num)`
+Special cases:
+- If any parameter is NULL, returns NULL
+- If string length is less than `<gram_num>`, returns 0
+- `<pattern>` and `<gram_num>` must be constants
+- Similarity of 1 does not necessarily mean strings are completely identical
-## Example
+## Examples
+1. Basic usage: Calculate similarity
```sql
-mysql> select ngram_search('123456789' , '12345' , 3);
+SELECT ngram_search('123456789', '12345', 3);
+```
+```text
+---------------------------------------+
| ngram_search('123456789', '12345', 3) |
+---------------------------------------+
| 0.6 |
+---------------------------------------+
+```
-mysql> select ngram_search("abababab","babababa",2);
+2. High similarity example
+```sql
+SELECT ngram_search('abababab', 'babababa', 2);
+```
+```text
+-----------------------------------------+
| ngram_search('abababab', 'babababa', 2) |
+-----------------------------------------+
| 1 |
+-----------------------------------------+
```
-## keywords
+
+3. String too short returns 0
+```sql
+SELECT ngram_search('ab', 'abc', 3);
+```
+```text
++----------------------------------+
+| ngram_search('ab', 'abc', 3) |
++----------------------------------+
+| 0 |
++----------------------------------+
+```
+
+4. NULL value handling
+```sql
+SELECT ngram_search(NULL, 'test', 2);
+```
+```text
++--------------------------------+
+| ngram_search(NULL, 'test', 2) |
++--------------------------------+
+| NULL |
++--------------------------------+
+```
+
+### Keywords
+
NGRAM_SEARCH,NGRAM,SEARCH
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/overlay.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/overlay.md
index 7afdd958105..bdad6ab244f 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/overlay.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/overlay.md
@@ -7,7 +7,7 @@
## Description
-The OVERLAY function is used to replace a part of a string with another string.
+The OVERLAY function is used to replace a substring at a specified position and length within a string. Starting from the specified position, it replaces the specified length of characters with a new string.
## Syntax
@@ -17,27 +17,28 @@ OVERLAY(<str>, <pos>, <len>, <newstr>)
## Parameters
-| Parameter | Description |
-| -- |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `<str>` | String that need to be replaced |
-| `<pos>` | The starting position of the string that needs to be replaced. Starting from 1. If the input position is not within the length range of `<str>`, the replacement will not be performed |
-| `<len>` | The length that needs to be replaced. When `<len>` is less than 0 or exceeds the length of the rest of the string, it will replace the rest of the string starting from `<pos>` |
-| `<newstr>` | String for replacement |
+| Parameter | Description |
+| ---------- | ----------------------------------------- |
+| `<str>` | The original string to be modified. Type: VARCHAR |
+| `<pos>` | The starting position for replacement (1-based). Type: INT |
+| `<len>` | The length of characters to replace. Type: INT |
+| `<newstr>` | The new string to use for replacement. Type: VARCHAR |
## Return Value
-Returns the string that replacing the specified length with a new string from the specified position. Special cases:
+Returns VARCHAR type, the new string after replacement.
-- If any Parameter is NULL, NULL will be returned.
-- If `<pos>` is not within the length range of `<str>`, no replacement will be performed.
-- When `<len>` is less than 0 or exceeds the length range of the remaining part of the `str`, the remaining string starting from `<pos>` will be replaced.
+Special cases:
+- If any parameter is NULL, returns NULL
+- If `<pos>` is less than 1 or exceeds string length, no replacement occurs and returns the original string
+- If `<len>` is less than 0 or exceeds the remaining length, replaces from `<pos>` to the end of the string
## Examples
+1. Basic usage: replace middle part
```sql
-select overlay('Quadratic', 3, 4, 'What');
+SELECT overlay('Quadratic', 3, 4, 'What');
```
-
```text
+------------------------------------+
| overlay('Quadratic', 3, 4, 'What') |
@@ -46,38 +47,38 @@ select overlay('Quadratic', 3, 4, 'What');
+------------------------------------+
```
+2. Negative length: replace to end
```sql
-select overlay('Quadratic', null, 4, 'What');
+SELECT overlay('Quadratic', 2, -1, 'Hi');
```
-
```text
-+---------------------------------------+
-| overlay('Quadratic', NULL, 4, 'What') |
-+---------------------------------------+
-| NULL |
-+---------------------------------------+
++-----------------------------------+
+| overlay('Quadratic', 2, -1, 'Hi') |
++-----------------------------------+
+| QHi |
++-----------------------------------+
```
+3. Position out of bounds: no replacement
```sql
-select overlay('Quadratic', -1, 4, 'What');
+SELECT overlay('Hello', 10, 2, 'X');
```
-
```text
-+-------------------------------------+
-| overlay('Quadratic', -1, 4, 'What') |
-+-------------------------------------+
-| Quadratic |
-+-------------------------------------+
++-------------------------------+
+| overlay('Hello', 10, 2, 'X') |
++-------------------------------+
+| Hello |
++-------------------------------+
```
+4. NULL value handling
```sql
-select overlay('Quadratic', 2, -4, 'What');
+SELECT overlay('Hello', NULL, 2, 'X');
```
-
```text
-+-------------------------------------+
-| overlay('Quadratic', 2, -4, 'What') |
-+-------------------------------------+
-| QWhat |
-+-------------------------------------+
++--------------------------------+
+| overlay('Hello', NULL, 2, 'X') |
++--------------------------------+
+| NULL |
++--------------------------------+
```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/parse-data-size.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/parse-data-size.md
index 50b5e2fb97f..3f3fa084a97 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/parse-data-size.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/parse-data-size.md
@@ -7,23 +7,7 @@
## Description
-Parse a string in the format of "value + unit" and convert the value into a number, where the value represents a fractional amount of the unit.
-
-If the input parameter is invalid, an error will be raised. The maximum return value is Int128 Max.
-
-**Data Storage Unit Table**
-
-| Unit | Description | Value |
-|------|-----------|------------|
-| B | Bytes | 1 |
-| kB | Kilobytes | 1024 |
-| MB | Megabytes | 1024² |
-| GB | Gigabytes | 1024³ |
-| TB | Terabytes | 1024⁴ |
-| PB | Petabytes | 1024⁵ |
-| EB | Exabytes | 1024⁶ |
-| ZB | Zettabytes | 1024⁷ |
-| YB | Yottabytes | 1024⁸ |
+The PARSE_DATA_SIZE function parses a string with storage units (such as "1.5GB") and converts it to a numeric value in bytes.
## Syntax
@@ -31,34 +15,53 @@ If the input parameter is invalid, an error will be raised. The maximum return v
PARSE_DATA_SIZE(<str>)
```
-## Parameters
+## Parameters
+
+| Parameter | Description |
+| -------- | ----------------------------------------- |
+| `<str>` | Data size string with unit (e.g., "100MB", "2.5GB"). Type: VARCHAR |
+
+## Return Value
-| Parameter | Description |
-| -- | -- |
-| `<str>` | The value is to be calculated |
+Returns BIGINT type, representing the numeric value converted to bytes.
-## Return Value
+Special cases:
+- Supported units (case-insensitive): B, kB, MB, GB, TB, PB, EB, ZB, YB
+- Units use base 1024 (e.g., 1kB = 1024B)
+- Supports decimals (e.g., "2.5MB")
+- If parameter format is invalid, returns error
+- If parameter is NULL, returns NULL
-The return number value represents a fractional amount of the unit.
+**Supported Units Table:**
-## Example
+| Unit | Name | Bytes |
+|------|------|-------|
+| B | Bytes | 1 |
+| kB | Kilobytes | 1024 |
+| MB | Megabytes | 1024² |
+| GB | Gigabytes | 1024³ |
+| TB | Terabytes | 1024⁴ |
+| PB | Petabytes | 1024⁵ |
+| EB | Exabytes | 1024⁶ |
+
+## Examples
+1. Basic usage: Parse bytes
```sql
-SELECT parse_data_size('1B');
+SELECT parse_data_size('1024B');
```
-
```text
-+-----------------------+
-| parse_data_size('1B') |
-+-----------------------+
-| 1 |
-+-----------------------+
++--------------------------+
+| parse_data_size('1024B') |
++--------------------------+
+| 1024 |
++--------------------------+
```
+2. Parse kilobytes
```sql
SELECT parse_data_size('1kB');
```
-
```text
+------------------------+
| parse_data_size('1kB') |
@@ -67,14 +70,62 @@ SELECT parse_data_size('1kB');
+------------------------+
```
+3. Parse megabytes with decimals
```sql
-SELECT parse_data_size('2.3MB');
+SELECT parse_data_size('2.5MB');
```
-
```text
+--------------------------+
-| parse_data_size('2.3MB') |
+| parse_data_size('2.5MB') |
+--------------------------+
-| 2411724 |
+| 2621440 |
+--------------------------+
```
+
+4. Parse gigabytes
+```sql
+SELECT parse_data_size('1GB');
+```
+```text
++------------------------+
+| parse_data_size('1GB') |
++------------------------+
+| 1073741824 |
++------------------------+
+```
+
+5. Parse terabytes
+```sql
+SELECT parse_data_size('1TB');
+```
+```text
++------------------------+
+| parse_data_size('1TB') |
++------------------------+
+| 1099511627776 |
++------------------------+
+```
+
+6. Unsupported unit, error
+```sql
+SELECT parse_data_size('1iB');
+```
+```text
+ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.3)[INVALID_ARGUMENT]Invalid Input argument "1iB" of function parse_data_size
+```
+
+7. Input NULL
+```sql
+SELECT parse_data_size(NULL);
+```
+```text
++-----------------------+
+| parse_data_size(NULL) |
++-----------------------+
+| NULL |
++-----------------------+
+```
+
+### Keywords
+
+ PARSE_DATA_SIZE
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/position.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/position.md
index 3d8fcd57c57..457a4afc260 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/position.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/position.md
@@ -7,6 +7,164 @@
## Description
+The POSITION function is used to find the position of a substring in a main string, with positions counting from 1.
+
+## Syntax
+
+```sql
+POSITION(<substr> IN <str>)
+
+POSITION(<substr>, <str> [, <pos>])
+```
+
+## Parameters
+
+| Parameter | Description |
+| -------- | ----------------------------------------------- |
+| `substr` | The substring to search for. Type: VARCHAR |
+| `str` | The main string to search within. Type: VARCHAR |
+| `pos` | Optional parameter specifying the starting position (from 1). If specified, search starts from this position |
+
+## Return Value
+
+Returns INT type, representing the position of the first occurrence of the substring in the main string.
+
+Search rules:
+- Returns position index starting from 1
+- If substring is not found, returns 0
+- If a starting position is specified, searches from that position
+- Search is case-sensitive
+
+Special cases:
+- If any parameter is NULL, returns NULL
+- If substring is an empty string, returns 1 (or the starting position)
+- If starting position exceeds string length, returns 0
+- If starting position is negative, searches from the beginning of the string
+
+## Examples
+
+1. Basic search (two syntax forms)
+```sql
+SELECT POSITION('bar' IN 'foobarbar'), POSITION('bar', 'foobarbar');
+```
+```text
++----------------------------------+--------------------------------+
+| POSITION('bar' IN 'foobarbar') | POSITION('bar', 'foobarbar') |
++----------------------------------+--------------------------------+
+| 4 | 4 |
++----------------------------------+--------------------------------+
+```
+
+2. Search with starting position
+```sql
+SELECT POSITION('bar', 'foobarbar', 5), POSITION('xbar', 'foobar');
+```
+```text
++-----------------------------------+----------------------------------+
+| POSITION('bar', 'foobarbar', 5) | POSITION('xbar', 'foobar') |
++-----------------------------------+----------------------------------+
+| 7 | 0 |
++-----------------------------------+----------------------------------+
+```
+
+3. NULL value handling
+```sql
+SELECT POSITION('test' IN NULL), POSITION(NULL, 'test');
+```
+```text
++--------------------------+------------------------+
+| POSITION('test' IN NULL) | POSITION(NULL, 'test') |
++--------------------------+------------------------+
+| NULL | NULL |
++--------------------------+------------------------+
+```
+
+4. Empty string handling
+```sql
+SELECT POSITION('' IN 'hello'), POSITION('world' IN '');
+```
+```text
++------------------------+------------------------+
+| POSITION('' IN 'hello') | POSITION('world' IN '') |
++------------------------+------------------------+
+| 1 | 0 |
++------------------------+------------------------+
+```
+
+5. Case-sensitive search
+```sql
+SELECT POSITION('World' IN 'Hello World'), POSITION('world' IN 'Hello World');
+```
+```text
++----------------------------------+----------------------------------+
+| POSITION('World' IN 'Hello World') | POSITION('world' IN 'Hello World') |
++----------------------------------+----------------------------------+
+| 7 | 0 |
++----------------------------------+----------------------------------+
+```
+
+6. Search from different positions
+```sql
+SELECT POSITION('a', 'banana', 1), POSITION('a', 'banana', 3);
+```
+```text
++-----------------------------+-----------------------------+
+| POSITION('a', 'banana', 1) | POSITION('a', 'banana', 3) |
++-----------------------------+-----------------------------+
+| 2 | 4 |
++-----------------------------+-----------------------------+
+```
+
+7. UTF-8 multi-byte characters
+```sql
+SELECT POSITION('ḍḍumai' IN 'ṭṛì ḍḍumai hello'), POSITION('hello', 'ṭṛì ḍḍumai hello', 8);
+```
+```text
++--------------------------------------+-------------------------------------------+
+| POSITION('ḍḍumai' IN 'ṭṛì ḍḍumai hello') | POSITION('hello', 'ṭṛì ḍḍumai hello', 8) |
++--------------------------------------+-------------------------------------------+
+| 5 | 13 |
++--------------------------------------+-------------------------------------------+
+```
+
+8. Special character search
+```sql
+SELECT POSITION('@' IN 'user@domain.com'), POSITION('.', 'user@domain.com', 10);
+```
+```text
++----------------------------------+--------------------------------------+
+| POSITION('@' IN 'user@domain.com') | POSITION('.', 'user@domain.com', 10) |
++----------------------------------+--------------------------------------+
+| 5 | 12 |
++----------------------------------+--------------------------------------+
+```
+
+9. Starting position beyond bounds
+```sql
+SELECT POSITION('test', 'hello world', 20), POSITION('test', 'hello world', 0);
+```
+```text
++--------------------------------------+-------------------------------------+
+| POSITION('test', 'hello world', 20) | POSITION('test', 'hello world', 0) |
++--------------------------------------+-------------------------------------+
+| 0 | 0 |
++--------------------------------------+-------------------------------------+
+```
+
+10. Search in numbers and symbols
+```sql
+SELECT POSITION('123' IN '456123789'), POSITION('-', 'phone: 123-456-7890', 11);
+```
+```text
++------------------------------+-------------------------------------------+
+| POSITION('123' IN '456123789') | POSITION('-', 'phone: 123-456-7890', 11) |
++------------------------------+-------------------------------------------+
+| 4 | 11 |
++------------------------------+-------------------------------------------+
+```
+
+## Description
+
The POSITION function is used to find the position of a substring within a string (counting from 1).
If the substring is not found, the function returns 0.
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/quote.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/quote.md
index d66b1286540..b0b215b39a2 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/quote.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/quote.md
@@ -5,24 +5,102 @@
}
---
-## quote
-### description
-#### Syntax
+## Description
-`VARCHAR quote(VARCHAR str)`
+The QUOTE function is used to wrap a string with single quotes and escape special characters within it, making it safe for use in SQL statements.
-Output all the strings in the argument as is and wrap them with ''
+## Syntax
-### example
+```sql
+QUOTE(<str>)
+```
+
+## Parameters
+
+| Parameter | Description |
+| ------- | ----------------------------------------- |
+| `<str>` | The input string to be quoted. Type: VARCHAR |
+
+## Return Value
+
+Returns VARCHAR type, the string wrapped with single quotes and with special characters escaped.
+
+Special cases:
+- If input is NULL, returns the string 'NULL' (without quotes)
+- Single quotes `'` are escaped to `\'`
+- Backslashes `\` are escaped to `\\`
+- `\\` is escaped to `\`
+- Empty string returns `''`
+## Examples
+
+1. Basic string quoting
```sql
-mysql> select quote('hello world!\\t');
-+-------------------------+
-| quote('hello world!\t') |
-+-------------------------+
-| 'hello world!\t' |
-+-------------------------+
+SELECT quote('hello');
+```
+```text
++----------------+
+| quote('hello') |
++----------------+
+| 'hello' |
++----------------+
```
-### keywords
- QUOTE
\ No newline at end of file
+2. String with single quotes (will be escaped)
+```sql
+SELECT quote("It's a test");
+```
+```text
++----------------------+
+| quote("It's a test") |
++----------------------+
+| 'It's a test' |
++----------------------+
+```
+
+3. NULL value handling
+```sql
+SELECT quote(NULL);
+```
+```text
++-------------+
+| quote(NULL) |
++-------------+
+| NULL |
++-------------+
+```
+
+4. Empty string handling
+```sql
+SELECT quote('');
+```
+```text
++-----------+
+| quote('') |
++-----------+
+| '' |
++-----------+
+```
+
+5. Backslash character
+```sql
+SELECT quote('aaa\\');
+```
+```text
++----------------+
+| quote('aaa\\') |
++----------------+
+| 'aaa\' |
++----------------+
+```
+
+```sql
+SELECT quote('aaa\cccb');
+```
+```text
++-------------------+
+| quote('aaa\cccb') |
++-------------------+
+| 'aaacccb' |
++-------------------+
+```
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/random_bytes.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/random_bytes.md
index 01bfc89a38f..8ba186ea3f7 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/random_bytes.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/random_bytes.md
@@ -7,44 +7,87 @@
## Description
-The RANDOM_BYTES function is used to generate a random byte sequence of the specified length.
+The RANDOM_BYTES function generates a random byte sequence of specified length. The returned byte sequence is represented as a hexadecimal string.
## Syntax
```sql
-RANDOM_BYTES( <len> )
+RANDOM_BYTES(<len>)
```
## Parameters
-| Parameter | Description |
-|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `<len>` | This parameter specifies the length of the random byte sequence to be generated. This value must be greater than 0; otherwise, an error will be occurred. |
+| Parameter | Description |
+| -------- | ----------------------------------------- |
+| `<len>` | Number of random bytes to generate. Type: INT |
## Return Value
-Returns a random byte sequence of the specified length, encoded in hexadecimal. Special cases:
+Returns VARCHAR type, a hexadecimal-encoded random byte sequence (prefixed with `0x`).
-- If any of the parameters is NULL, NULL will be returned.
+Special cases:
+- `<len>` must be greater than 0, otherwise returns error
+- If parameter is NULL, returns NULL
+- Each invocation generates a random result
## Examples
+1. Basic usage: Generate 8-byte random sequence
```sql
-select random_bytes(7);
+SELECT random_bytes(8);
+```
+```text
++--------------------+
+| random_bytes(8) |
++--------------------+
+| 0x1a2b3c4d5e6f7089 |
++--------------------+
```
+2. Generate short sequence
+```sql
+SELECT random_bytes(4);
+```
```text
-+------------------+
-| random_bytes(7) |
-+------------------+
-| 0x869684a082ab4b |
-+------------------+
++----------------+
+| random_bytes(4) |
++----------------+
+| 0xab12cd34 |
++----------------+
```
+3. Invalid parameter: Negative number
```sql
-select random_bytes(-1);
+SELECT random_bytes(-1);
+```
+```text
+ERROR 1105 (HY000): errCode = 2, detailMessage = (10.16.10.3)[INVALID_ARGUMENT]argument -1 of function random_bytes at row 0 was invalid.
```
+4. NULL value handling
+```sql
+SELECT random_bytes(NULL);
+```
```text
-(1105, 'errCode = 2, detailMessage = (127.0.0.1)[INVALID_ARGUMENT]argument -1 of function random_bytes at row 0 was invalid.')
++--------------------+
+| random_bytes(NULL) |
++--------------------+
+| NULL |
++--------------------+
```
+
+5. Generate longer sequence (16 bytes)
+```sql
+SELECT random_bytes(16);
+```
+```text
++------------------------------------+
+| random_bytes(16) |
++------------------------------------+
+| 0x1a2b3c4d5e6f708192a3b4c5d6e7f809 |
++------------------------------------+
+```
+
+### Keywords
+
+ RANDOM_BYTES
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/repeat.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/repeat.md
index 2c00e5618a0..ee5ef0280ef 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/repeat.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/repeat.md
@@ -7,6 +7,161 @@
## Description
+The REPEAT function is used to repeat a specified string a specified number of times to generate a new string. This function is commonly used for generating padding characters, creating separators, or generating test data.
+
+## Syntax
+
+```sql
+REPEAT(<str>, <count>)
+```
+
+## Parameters
+
+| Parameter | Description |
+| -- | -- |
+| `<str>` | The source string to repeat. Type: VARCHAR |
+| `<count>` | The number of times to repeat, must be a non-negative integer. Type: INT |
+
+## Return Value
+
+Returns VARCHAR type, representing the string repeated the specified number of times.
+
+Repeat rules:
+- When count is greater than 0, returns the result of str repeated count times
+- When count equals 0, returns an empty string
+- When count is less than 0, returns an empty string
+- If the resulting string is too long, it may be subject to string length limitations
+
+Special cases:
+- If any parameter is NULL, returns NULL
+- If str is an empty string, returns an empty string regardless of count
+- If count is 0, returns an empty string
+- If count is negative, returns an empty string
+
+## Examples
+
+1. Basic character repetition
+```sql
+SELECT REPEAT('a', 3);
+```
+```text
++----------------+
+| REPEAT('a', 3) |
++----------------+
+| aaa |
++----------------+
+```
+
+2. Multi-character string repetition
+```sql
+SELECT REPEAT('hello', 2);
+```
+```text
++--------------------+
+| REPEAT('hello', 2) |
++--------------------+
+| hellohello |
++--------------------+
+```
+
+3. Zero repetitions
+```sql
+SELECT REPEAT('test', 0);
+```
+```text
++-------------------+
+| REPEAT('test', 0) |
++-------------------+
+| |
++-------------------+
+```
+
+4. Negative repetitions
+```sql
+SELECT REPEAT('a', -1);
+```
+```text
++-----------------+
+| REPEAT('a', -1) |
++-----------------+
+| |
++-----------------+
+```
+
+5. NULL value handling
+```sql
+SELECT REPEAT(NULL, 3), REPEAT('a', NULL);
+```
+```text
++------------------+-------------------+
+| REPEAT(NULL, 3) | REPEAT('a', NULL) |
++------------------+-------------------+
+| NULL | NULL |
++------------------+-------------------+
+```
+
+6. Empty string repetition
+```sql
+SELECT REPEAT('', 5);
+```
+```text
++----------------+
+| REPEAT('', 5) |
++----------------+
+| |
++----------------+
+```
+
+7. Special character repetition
+```sql
+SELECT REPEAT('-', 10), REPEAT('*', 5);
+```
+```text
++------------------+-----------------+
+| REPEAT('-', 10) | REPEAT('*', 5) |
++------------------+-----------------+
+| ---------- | ***** |
++------------------+-----------------+
+```
+
+8. UTF-8 character repetition
+```sql
+SELECT REPEAT('ṭṛì', 3), REPEAT('ḍḍu', 2);
+```
+```text
++-------------------+-------------------+
+| REPEAT('ṭṛì', 3) | REPEAT('ḍḍu', 2) |
++-------------------+-------------------+
+| ṭṛìṭṛìṭṛì | ḍḍuḍḍu |
++-------------------+-------------------+
+```
+
+9. Mixed numbers and symbols
+```sql
+SELECT REPEAT('123', 3), REPEAT('@#', 4);
+```
+```text
++-------------------+------------------+
+| REPEAT('123', 3) | REPEAT('@#', 4) |
++-------------------+------------------+
+| 123123123 | @#@#@#@# |
++-------------------+------------------+
+```
+
+10. UTF-8 character repetition
+```sql
+SELECT REPEAT('ṭṛìṭṛì', 3);
+```
+```text
++--------------------------------------------------+
+| REPEAT('ṭṛìṭṛì', 3) |
++--------------------------------------------------+
+| ṭṛìṭṛìṭṛìṭṛìṭṛìṭṛì |
++--------------------------------------------------+
+```
+
+## Description
+
The REPEAT function is used to repeat a string a specified number of times.
## Syntax
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/replace-empty.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/replace-empty.md
index b351abfaac5..b7e760bf7f9 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/replace-empty.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/replace-empty.md
@@ -7,13 +7,9 @@
## Description
-The REPLACE_EMPTY function is used to replace a part of the characters in a string with other characters. Unlike the [REPLACE](./replace.md) function, when old is an empty string, the new string will be inserted before each character of the str string and at the end of the str string.
+The REPLACE_EMPTY function is used to replace a part of characters in a string with other characters. Unlike the [REPLACE](./replace.md) function, when `old` is an empty string, the `new` string is inserted before each character of the `str` string and at the end of the `str` string.
-Apart from this, all other behaviors are exactly the same as the REPLACE() function.
-
-This function is mainly used to be compatible with Presto and Trino, and its behavior is exactly the same as the `REPLACE()` function in Presto and Trino.
-
-Supported since version 2.1.5.
+This function is mainly used to be compatible with Presto and Trino, and its behavior is exactly the same as the `REPLACE()` function in Presto and Trino. Supported since version 2.1.5.
## Syntax
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/replace.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/replace.md
index 7c1046f32da..c73b20c1bfd 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/replace.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/replace.md
@@ -7,38 +7,100 @@
## Description
-The REPLACE function is used to replace a part of characters in a string with other characters.
+The REPLACE function is used to replace all occurrences of a specified substring in a string with a new substring. This function replaces all matching instances of the substring in the string, performing a global replace operation.
+
+**Difference from REPLACE_EMPTY function:**
+- `REPLACE()` replaces the specified substring, including empty strings
+- `REPLACE_EMPTY()` is specifically used to replace empty values or empty strings with a specified value
## Syntax
```sql
-REPLACE ( <str>, <old>, <new> )
+REPLACE(<str>, <old>, <new>)
```
## Parameters
-| Parameter | Description |
-|---------|-----------------------------------------------------------------------------------------------------|
-| `<str>` | The string that needs to be replaced. |
-| `<old>` | The substring that needs to be replaced. If `<old>` is not in `<str>`, no replacement will be made. |
-| `<new>` | The new substring used to replace `<old>`. |
+| Parameter | Description |
+|-----------|-------------|
+| `<str>` | The source string where replacement will occur. Type: VARCHAR |
+| `<old>` | The target substring to be replaced. If not found in str, no replacement occurs. Type: VARCHAR |
+| `<new>` | The new substring used to replace old. Type: VARCHAR |
## Return Value
-Returns the new string after replacing the substring. Special cases:
+Returns VARCHAR type, representing the new string after replacement.
+
+Replacement rules:
+- Replaces all matching old substrings in the string
+- Replacement is case-sensitive
+- If old is an empty string, returns the original string (no operation performed)
+- If new is an empty string, effectively deletes all matching old substrings
-- If any Parameter is NULL, NULL will be returned.
+Special cases:
+- If any parameter is NULL, returns NULL
+- If str is an empty string, returns an empty string
+- If old is an empty string, returns the original str (no replacement)
+- If old is not found in str, returns the original str
## Examples
+1. Basic replacement operation
```sql
-SELECT replace('hello world', 'world', 'universe');
+SELECT REPLACE('hello world', 'world', 'universe');
```
-
```text
+---------------------------------------------+
-| replace('hello world', 'world', 'universe') |
+| REPLACE('hello world', 'world', 'universe') |
+---------------------------------------------+
| hello universe |
+---------------------------------------------+
```
+
+2. Replace multiple matches
+```sql
+SELECT REPLACE('apple apple apple', 'apple', 'orange');
+```
+```text
++------------------------------------------------+
+| REPLACE('apple apple apple', 'apple', 'orange') |
++------------------------------------------------+
+| orange orange orange |
++------------------------------------------------+
+```
+
+3. Delete substring (replace with empty string)
+```sql
+SELECT REPLACE('banana', 'a', '');
+```
+```text
++---------------------------+
+| REPLACE('banana', 'a', '') |
++---------------------------+
+| bnn |
++---------------------------+
+```
+
+4. NULL value handling
+```sql
+SELECT REPLACE(NULL, 'old', 'new'), REPLACE('test', NULL, 'new'), REPLACE('test', 'old', NULL);
+```
+```text
++------------------------------+------------------------------+------------------------------+
+| REPLACE(NULL, 'old', 'new') | REPLACE('test', NULL, 'new') | REPLACE('test', 'old', NULL) |
++------------------------------+------------------------------+------------------------------+
+| NULL | NULL | NULL |
++------------------------------+------------------------------+------------------------------+
+```
+
+5. UTF-8 character replacement
+```sql
+SELECT REPLACE('ṭṛì ḍḍumai test ṭṛì ḍḍumannàri', 'ṭṛì', 'replaced');
+```
+```text
++-----------------------------------------------------------+
+| REPLACE('ṭṛì ḍḍumai test ṭṛì ḍḍumannàri', 'ṭṛì', 'replaced') |
++-----------------------------------------------------------+
+| replaced ḍḍumai test replaced ḍḍumannàri |
++-----------------------------------------------------------+
+```
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/reverse.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/reverse.md
index 0628c8b7474..def31358c0c 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/reverse.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/reverse.md
@@ -7,6 +7,156 @@
## Description
+The REVERSE function is used to reverse the order of an input sequence. For string arguments, it returns a string with the character order reversed; for array arguments, it returns an array with the element order reversed. This function reverses by character and can correctly handle UTF-8 multi-byte characters.
+
+## Syntax
+
+```sql
+REVERSE(<seq>)
+```
+
+## Parameters
+
+| Parameter | Description |
+|---------|----------------|
+| `<seq>` | The string or array to reverse. Type: VARCHAR or ARRAY |
+
+## Return Value
+
+Returns the reversed sequence of the same type as the input:
+- String input: Returns VARCHAR type, a string with reversed character order
+- Array input: Returns ARRAY type, an array with reversed element order
+
+Special cases:
+- If parameter is NULL, returns NULL
+- If string is empty, returns empty string
+- If array is empty, returns empty array
+- A single-character string remains the same after reversal
+
+## Examples
+
+1. Basic string reversal
+```sql
+SELECT REVERSE('hello');
+```
+```text
++------------------+
+| REVERSE('hello') |
++------------------+
+| olleh |
++------------------+
+```
+
+2. Array element reversal
+```sql
+SELECT REVERSE(['hello', 'world']);
+```
+```text
++-----------------------------+
+| REVERSE(['hello', 'world']) |
++-----------------------------+
+| ["world", "hello"] |
++-----------------------------+
+```
+
+3. NULL value handling
+```sql
+SELECT REVERSE(NULL);
+```
+```text
++---------------+
+| REVERSE(NULL) |
++---------------+
+| NULL |
++---------------+
+```
+
+4. Empty string and empty array
+```sql
+SELECT REVERSE(''), REVERSE([]);
+```
+```text
++-------------+-------------+
+| REVERSE('') | REVERSE([]) |
++-------------+-------------+
+| | [] |
++-------------+-------------+
+```
+
+5. Single character and single element
+```sql
+SELECT REVERSE('A'), REVERSE(['single']);
+```
+```text
++--------------+--------------------+
+| REVERSE('A') | REVERSE(['single']) |
++--------------+--------------------+
+| A | ["single"] |
++--------------+--------------------+
+```
+
+6. Numbers and special characters
+```sql
+SELECT REVERSE('12345'), REVERSE('!@#$%');
+```
+```text
++------------------+------------------+
+| REVERSE('12345') | REVERSE('!@#$%') |
++------------------+------------------+
+| 54321 | %$#@! |
++------------------+------------------+
+```
+
+7. UTF-8 multi-byte characters
+```sql
+SELECT REVERSE('ṭṛì ḍḍumai'), REVERSE('ḍḍumannàri');
+```
+```text
++-----------------------+------------------------+
+| REVERSE('ṭṛì ḍḍumai') | REVERSE('ḍḍumannàri') |
++-----------------------+------------------------+
+| iamuḍḍ ìṛṭ | irànnaumuḍḍ |
++-----------------------+------------------------+
+```
+
+8. Mixed character types
+```sql
+SELECT REVERSE('Hello123'), REVERSE('test@email.com');
+```
+```text
++---------------------+--------------------------+
+| REVERSE('Hello123') | REVERSE('test@email.com') |
++---------------------+--------------------------+
+| 321olleH | moc.liame@tset |
++---------------------+--------------------------+
+```
+
+9. Multi-element array
+```sql
+SELECT REVERSE([1, 2, 3, 4, 5]), REVERSE(['a', 'b', 'c']);
+```
+```text
++---------------------------+------------------------+
+| REVERSE([1, 2, 3, 4, 5]) | REVERSE(['a', 'b', 'c']) |
++---------------------------+------------------------+
+| [5, 4, 3, 2, 1] | ["c", "b", "a"] |
++---------------------------+------------------------+
+```
+
+10. Palindrome test
+```sql
+SELECT REVERSE('level'), REVERSE('12321');
+```
+```text
++------------------+-------------------+
+| REVERSE('level') | REVERSE('12321') |
++------------------+-------------------+
+| level | 12321 |
++------------------+-------------------+
+```
+
+## Description
+
The REVERSE function is used to reverse the order of characters in a string or the order of elements in an array.
## Syntax
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/rpad.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/rpad.md
index ad68e3572a2..165a1500591 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/rpad.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/rpad.md
@@ -5,67 +5,160 @@
}
---
+
## Description
-Used to pad the specified character on the right side of the original string until met the specified length.
+The RPAD function (Right Padding) is used to pad the right side of a string with specified characters until it reaches a specified length. If the target length is less than the original string length, the string is truncated. This function calculates by character length, not byte length.
## Syntax
```sql
-RPAD ( <str> , <len> , <pad>)
+RPAD(<str>, <len>, <pad>)
```
## Parameters
-| Parameter | Description |
-|---------|-------------------------------------------------------------------------------------------------------------|
-| `<str>` | The string to be padded. |
-| `<len>` | The total length of the final result string, which represents character length rather than the byte length. |
-| `<pad>` | The string used for padding. |
+| Parameter | Description |
+|---------|----------------------------|
+| `<str>` | The source string to be padded. Type: VARCHAR |
+| `<len>` | The target character length (not byte length). Type: INT |
+| `<pad>` | The string to pad with. Type: VARCHAR |
## Return Value
-Returns the padded string. Special cases:
+Returns VARCHAR type, representing the padded or truncated string.
+
+Padding rules:
+- If len > original string length: repeatedly pad with pad string on the right until total length reaches len
+- If len = original string length: return the original string
+- If len < original string length: truncate the string, returning only the first len characters
+- The pad string is used cyclically, possibly using only partial characters
+- Calculated by character length, supports UTF-8 multi-byte characters
-- If any Parameter is NULL, NULL will be returned.
-- If `<pad>` is empty and `<len>` is greater than the length of `<str>`, the return value is an empty string.
-- If `<len>` is less than the length of `<str>`, the string obtained by truncating `<str>` to `<len>` is returned.
-- If `<len>` is less than 0, the return value is NULL.
+Special cases:
+- If any parameter is NULL, returns NULL
+- If pad is an empty string and len > str length, returns an empty string
+- If len is 0, returns an empty string
+- If len is negative, returns NULL
## Examples
+1. Basic right padding
```sql
-SELECT rpad('hello', 1, '');
+SELECT RPAD('hi', 5, 'xy'), RPAD('hello', 8, '*');
+```
+```text
++---------------------+-----------------------+
+| RPAD('hi', 5, 'xy') | RPAD('hello', 8, '*') |
++---------------------+-----------------------+
+| hixyx | hello*** |
++---------------------+-----------------------+
```
+2. String truncation
+```sql
+SELECT RPAD('hello', 1, ''), RPAD('hello world', 5, 'x');
+```
```text
-+----------------------+
-| rpad('hello', 1, '') |
-+----------------------+
-| h |
-+----------------------+
++----------------------+------------------------------+
+| RPAD('hello', 1, '') | RPAD('hello world', 5, 'x') |
++----------------------+------------------------------+
+| h | hello |
++----------------------+------------------------------+
```
+3. NULL value handling
```sql
-SELECT rpad('hello', 10, 'world');
+SELECT RPAD(NULL, 5, 'x'), RPAD('hi', NULL, 'x'), RPAD('hi', 5, NULL);
+```
+```text
++---------------------+------------------------+----------------------+
+| RPAD(NULL, 5, 'x') | RPAD('hi', NULL, 'x') | RPAD('hi', 5, NULL) |
++---------------------+------------------------+----------------------+
+| NULL | NULL | NULL |
++---------------------+------------------------+----------------------+
```
+4. Empty string and zero length
+```sql
+SELECT RPAD('', 0, ''), RPAD('hi', 0, 'x'), RPAD('', 5, '*');
+```
```text
-+----------------------------+
-| rpad('hello', 10, 'world') |
-+----------------------------+
-| helloworld |
-+----------------------------+
++-----------------+-------------------+--------------------+
+| RPAD('', 0, '') | RPAD('hi', 0, 'x') | RPAD('', 5, '*') |
++-----------------+-------------------+--------------------+
+| | | ***** |
++-----------------+-------------------+--------------------+
```
+5. Empty padding string
```sql
-SELECT rpad('hello', 10, '');
+SELECT RPAD('hello', 10, ''), RPAD('hi', 2, '');
+```
+```text
++-----------------------+-------------------+
+| RPAD('hello', 10, '') | RPAD('hi', 2, '') |
++-----------------------+-------------------+
+| | hi |
++-----------------------+-------------------+
```
+6. Long padding string and cycling
+```sql
+SELECT RPAD('hello', 10, 'world'), RPAD('X', 7, 'ABC');
+```
```text
-+-----------------------+
-| rpad('hello', 10, '') |
-+-----------------------+
-| |
-+-----------------------+
++----------------------------+----------------------+
+| RPAD('hello', 10, 'world') | RPAD('X', 7, 'ABC') |
++----------------------------+----------------------+
+| helloworld | XABCABC |
++----------------------------+----------------------+
+```
+
+7. UTF-8 multi-byte character padding
+```sql
+SELECT RPAD('hello', 10, 'ṭṛì'), RPAD('ḍḍumai', 3, 'x');
```
+```text
++---------------------------+--------------------------+
+| RPAD('hello', 10, 'ṭṛì') | RPAD('ḍḍumai', 3, 'x') |
++---------------------------+--------------------------+
+| helloṭṛìṭṛ | ḍḍu |
++---------------------------+--------------------------+
+```
+
+8. Number string formatting
+```sql
+SELECT RPAD('$99', 8, '.'), RPAD('Item1', 10, ' ');
+```
+```text
++---------------------+------------------------+
+| RPAD('$99', 8, '.') | RPAD('Item1', 10, ' ') |
++---------------------+------------------------+
+| $99..... | Item1 |
++---------------------+------------------------+
+```
+
+9. Table column alignment
+```sql
+SELECT RPAD('Name', 15, ' '), RPAD('Price', 10, ' ');
+```
+```text
++------------------------+------------------------+
+| RPAD('Name', 15, ' ') | RPAD('Price', 10, ' ') |
++------------------------+------------------------+
+| Name | Price |
++------------------------+------------------------+
+```
+
+10. Negative length handling
+```sql
+SELECT RPAD('hello', -1, 'x'), RPAD('test', -5, '*');
+```
+```text
++------------------------+------------------------+
+| RPAD('hello', -1, 'x') | RPAD('test', -5, '*') |
++------------------------+------------------------+
+| NULL | NULL |
++------------------------+------------------------+
+```
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/rtrim-in.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/rtrim-in.md
index c796f66a7ec..210a22b5efa 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/rtrim-in.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/rtrim-in.md
@@ -8,6 +8,7 @@
## Description
The RTRIM_IN function removes specified characters from the right side of a string. When no character set is specified, it removes trailing spaces by default. When a character set is specified, it removes all specified characters from the right side (regardless of their order in the set).
+
The key feature of RTRIM_IN is that it removes any combination of characters from the specified set, while the RTRIM function removes characters based on exact string matching.
## Syntax
@@ -17,9 +18,9 @@ RTRIM_IN(<str>[, <rhs>])
```
## Parameters
-| Parameter | Description |
+| Parameter | Description |
| --------- | ---------------------------------------------------------------------- |
-| `<str>` | The string to be processed. Type: VARCHAR |
+| `<str>` | The string to be processed. Type: VARCHAR |
| `<rhs>` | Optional parameter, the set of characters to be removed. Type: VARCHAR |
## Return Value
@@ -47,7 +48,6 @@ SELECT rtrim_in('ab d ') str;
2. Remove specified character set
```sql
--- RTRIM_IN removes any 'a' and 'b' characters from the right end
SELECT rtrim_in('ababccaab', 'ab') str;
```
```text
@@ -60,7 +60,7 @@ SELECT rtrim_in('ababccaab', 'ab') str;
3. Comparison with RTRIM function
```sql
-SELECT rtrim_in('ababccaab', 'ab'),rtrim('ababccaab', 'ab');
+SELECT rtrim_in('ababccaab', 'ab'), rtrim('ababccaab', 'ab');
```
```text
+-----------------------------+--------------------------+
@@ -68,4 +68,56 @@ SELECT rtrim_in('ababccaab', 'ab'),rtrim('ababccaab', 'ab');
+-----------------------------+--------------------------+
| ababcc | ababcca |
+-----------------------------+--------------------------+
-```
\ No newline at end of file
+```
+
+4. Character set order does not matter
+```sql
+SELECT rtrim_in('Helloabc', 'cba');
+```
+```text
++-----------------------------+
+| rtrim_in('Helloabc', 'cba') |
++-----------------------------+
+| Hello |
++-----------------------------+
+```
+
+5. UTF-8 character support
+```sql
+SELECT rtrim_in('ṭṛì ḍḍumai+++', '+');
+```
+```text
++------------------------------------+
+| rtrim_in('ṭṛì ḍḍumai+++', '+') |
++------------------------------------+
+| ṭṛì ḍḍumai |
++------------------------------------+
+```
+
+6. NULL value handling
+```sql
+SELECT rtrim_in(NULL, 'abc');
+```
+```text
++------------------------+
+| rtrim_in(NULL, 'abc') |
++------------------------+
+| NULL |
++------------------------+
+```
+
+7. Empty character handling
+```sql
+SELECT rtrim_in('', 'abc'), rtrim_in('abc', '');
+```
+```text
++---------------------+---------------------+
+| rtrim_in('', 'abc') | rtrim_in('abc', '') |
++---------------------+---------------------+
+| | abc |
++---------------------+---------------------+
+```
+
+### Keywords
+
+ RTRIM_IN, RTRIM
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/rtrim.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/rtrim.md
index ded7ac16098..91880350a93 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/rtrim.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/rtrim.md
@@ -5,36 +5,39 @@
}
---
+
## Description
-The RTRIM function is used to remove consecutive spaces or specified characters from the right side (trailing) of a string.
+The RTRIM function is used to remove consecutive spaces or specified strings from the right side (trailing) of a string. If the second parameter is not specified, trailing spaces are removed; if specified, the function removes the specified complete string from the right side.
## Syntax
```sql
-RTRIM( <str> [, <trim_chars> ] )
+RTRIM(<str>[, <rhs>])
```
## Parameters
-| Parameter | Description |
-|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| `<str>` | The string that needs to be trimmed. |
-| `<trim_chars>` | Optional parameter. If this parameter is provided, the RTRIM function will remove all characters in `<trim_chars>` that appear on the right side of `<str>`. If this parameter is not provided, the RTRIM function will only remove the space characters on the right side of `<str>`. |
+| Parameter | Description |
+| --------- | ----------- |
+| `<str>` | The string to be processed. Type: VARCHAR |
+| `<rhs>` | Optional parameter, trailing characters to be trimmed. Type: VARCHAR |
## Return Value
-Returns a string with trailing spaces or `<trim_chars>` removed. Special cases:
-
-- If any Parameter is NULL, NULL will be returned.
+Returns a value of type VARCHAR.
+Special cases:
+- If any parameter is NULL, NULL is returned
+- If rhs is not specified, removes trailing spaces
+- If rhs is specified, removes the complete rhs string (not character-by-character)
## Examples
+1. Remove trailing spaces
```sql
SELECT rtrim('ab d ') str;
```
-
```text
+------+
| str |
@@ -43,10 +46,10 @@ SELECT rtrim('ab d ') str;
+------+
```
+2. Remove specified trailing string
```sql
-SELECT rtrim('ababccaab','ab') str;
+SELECT rtrim('ababccaab', 'ab') str;
```
-
```text
+---------+
| str |
@@ -54,3 +57,79 @@ SELECT rtrim('ababccaab','ab') str;
| ababcca |
+---------+
```
+
+3. UTF-8 character support
+```sql
+SELECT rtrim('ṭṛì ḍḍumai ');
+```
+```text
++---------------------------+
+| rtrim('ṭṛì ḍḍumai ') |
++---------------------------+
+| ṭṛì ḍḍumai |
++---------------------------+
+```
+
+4. No matching suffix, return original string
+```sql
+SELECT rtrim('Hello World', 'xyz');
+```
+```text
++---------------------------------+
+| rtrim('Hello World', 'xyz') |
++---------------------------------+
+| Hello World |
++---------------------------------+
+```
+
+5. NULL value handling
+```sql
+SELECT rtrim(NULL), rtrim('Hello', NULL);
+```
+```text
++-------------+------------------------+
+| rtrim(NULL) | rtrim('Hello', NULL) |
++-------------+------------------------+
+| NULL | NULL |
++-------------+------------------------+
+```
+
+6. Empty string handling
+```sql
+SELECT rtrim(''), rtrim('abc', '');
+```
+```text
++-----------+-------------------+
+| rtrim('') | rtrim('abc', '') |
++-----------+-------------------+
+| | abc |
++-----------+-------------------+
+```
+
+7. Repeated trailing pattern removal
+```sql
+SELECT rtrim('abcabcabc', 'abc');
+```
+```text
++-------------------------------+
+| rtrim('abcabcabc', 'abc') |
++-------------------------------+
+| |
++-------------------------------+
+```
+
+8. Multiple occurrences, remove only trailing match
+```sql
+SELECT rtrim('HelloHelloWorld', 'Hello');
+```
+```text
++---------------------------------------+
+| rtrim('HelloHelloWorld', 'Hello') |
++---------------------------------------+
+| HelloHelloWorld |
++---------------------------------------+
+```
+
+### Keywords
+
+ RTRIM
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/soundex.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/soundex.md
index aa5f15e64b3..aa31af96b0f 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/soundex.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/soundex.md
@@ -7,96 +7,147 @@
## Description
-The SOUNDEX function computes the [American Soundex](https://en.wikipedia.org/wiki/Soundex) value, which consists of the first letter followed by a three-digit sound code that represents the English pronunciation of the input string.
+The SOUNDEX function computes the [Soundex encoding](https://en.wikipedia.org/wiki/Soundex) of a string. Soundex is a phonetic algorithm that encodes English words into codes representing their pronunciation, so words with similar pronunciation will have the same encoding.
-The function ignores all non-letter characters in the string.
+Encoding rule: Returns a 4-character code consisting of one uppercase letter followed by three digits (e.g., S530).
## Syntax
```sql
-SOUNDEX ( <expr> )
+SOUNDEX(<expr>)
```
-## Arguments
+## Parameters
-| Argument | Description |
-|----------|----------------------------|
-| `<expr>` | The string to compute for, only accept ASCII characters. |
+| Parameter | Description |
+| -------- | ----------------------------------------- |
+| `<expr>` | The string to compute Soundex encoding for (only supports ASCII characters). Type: VARCHAR |
## Return Value
-Returns a VARCHAR(4) string consisting of an uppercase letter followed by a three-digit numeric sound code representing English pronunciation.
+Returns VARCHAR(4) type, representing the Soundex encoding of the string.
-If the string is empty or contains no letter characters, an empty string is returned.
+Special cases:
+- If the argument is NULL, returns NULL
+- If the string is empty or contains no letters, returns an empty string
+- Only processes ASCII letters, ignoring other characters
+- Non-ASCII characters will cause the function to throw an error
-If the string to be processed contains non-ASCII characters, the function will throw an exception during the calculation process.
+## Examples
-If the input is NULL, NULL is returned.
+1. Basic usage: word encoding
+```sql
+SELECT soundex('Doris');
+```
+```text
++------------------+
+| soundex('Doris') |
++------------------+
+| D620 |
++------------------+
+```
-## Examples
+2. Words with similar pronunciation have the same encoding
+```sql
+SELECT soundex('Smith'), soundex('Smyth');
+```
+```text
++------------------+------------------+
+| soundex('Smith') | soundex('Smyth') |
++------------------+------------------+
+| S530 | S530 |
++------------------+------------------+
+```
+
+3. Empty string processing
+```sql
+SELECT soundex('');
+```
+```text
++-------------+
+| soundex('') |
++-------------+
+| |
++-------------+
+```
+
+4. NULL value handling
+
+```sql
+SELECT soundex(NULL);
+```
+
+```text
++---------------+
+| soundex(NULL) |
++---------------+
+| NULL |
++---------------+
+```
+
+5. Empty string returns empty string
-The following table simulates a list of names.
```sql
-CREATE TABLE IF NOT EXISTS soundex_test (
- name VARCHAR(20)
-) DISTRIBUTED BY HASH(name) BUCKETS 1
-PROPERTIES ("replication_num" = "1");
+SELECT soundex('');
+```
-INSERT INTO soundex_test (name) VALUES
-('Doris'),
-('Smith'), ('Smyth'),
-('H'), ('P'), ('Lee'),
-('Robert'), ('R@b-e123rt'),
-('123@*%'), (''),
-('Ashcraft'), ('Honeyman'), ('Pfister'), (NULL);
+```text
++-------------+
+| soundex('') |
++-------------+
+| |
++-------------+
```
+6. Non-letter characters only return empty string
+
```sql
-SELECT name, soundex(name) AS IDX FROM soundex_test;
+SELECT soundex('123@*%');
```
+
```text
-+------------+------+
-| NULL | NULL |
-| | |
-| 123@*% | |
-| Ashcraft | A261 |
-| Doris | D620 |
-| H | H000 |
-| Honeyman | H555 |
-| Lee | L000 |
-| P | P000 |
-| Pfister | P236 |
-| R@b-e123rt | R163 |
-| Robert | R163 |
-| Smith | S530 |
-| Smyth | S530 |
-+------------+------+
-```
-
-Behavior for non-ASCII characters:
-
-- When Doris processes the input string character by character, if it encounters a non-ASCII character before finishing the computation, it will throw an error. Example:
++-------------------+
+| soundex('123@*%') |
++-------------------+
+| |
++-------------------+
+```
+
+7. Ignoring non-letter characters
```sql
-SELECT SOUNDEX('你好');
--- ERROR 1105 (HY000): errCode = 2, detailMessage = (127.0.0.1)[INVALID_ARGUMENT]soundex only supports ASCII
+SELECT soundex('R@b-e123rt'), soundex('Robert');
```
+```text
++-----------------------+-------------------+
+| soundex('R@b-e123rt') | soundex('Robert') |
++-----------------------+-------------------+
+| R163 | R163 |
++-----------------------+-------------------+
+```
+
+9. Non-ASCII characters only error example
+
```sql
--- After processing `Doris` it produces D62 (still missing one digit, not a complete 4-character code)
--- When it reads the non-ASCII character `你`, the function errors
-SELECT SOUNDEX('Doris 你好');
--- ERROR 1105 (HY000): errCode = 2, detailMessage = (127.0.0.1)[INVALID_ARGUMENT]soundex only supports ASCII
+SELECT soundex('你好');
+```
+```text
+ERROR 1105 (HY000): errCode = 2, detailMessage = Not Supported: Not Supported: soundex only supports ASCII, but got: 你
```
```sql
-SELECT SOUNDEX('Apache Doris 你好');
+SELECT soundex('Apache Doris 你好');
```
```text
+--------------------------------+
-| SOUNDEX('Apache Doris 你好') |
+| soundex('Apache Doris 你好') |
+--------------------------------+
| A123 |
+--------------------------------+
-```
\ No newline at end of file
+```
+
+### Keywords
+
+ SOUNDEX
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/space.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/space.md
index fd9e16fd6ac..4eda43901ad 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/space.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/space.md
@@ -30,22 +30,34 @@ Returns a string consisting of the specified number of spaces. Special cases:
## Examples
+1. Generate specified number of spaces
```sql
-SELECT space(10);
+SELECT space(5);
```
-
```text
-+------------+
-| space(10) |
-+------------+
-| |
-+------------+
++----------+
+| space(5) |
++----------+
+| |
++----------+
```
+2. Zero or negative number handling
```sql
-SELECT space(null);
+SELECT space(0), space(-5);
+```
+```text
++----------+-----------+
+| space(0) | space(-5) |
++----------+-----------+
+| | |
++----------+-----------+
```
+3. NULL value handling
+```sql
+SELECT space(NULL);
+```
```text
+-------------+
| space(NULL) |
@@ -53,3 +65,19 @@ SELECT space(null);
| NULL |
+-------------+
```
+
+4. Use with other functions
+```sql
+SELECT CONCAT('Hello', space(3), 'World');
+```
+```text
++------------------------------------+
+| concat('Hello', space(3), 'World') |
++------------------------------------+
+| Hello World |
++------------------------------------+
+```
+
+### Keywords
+
+ SPACE
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/split-by-regexp.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/split-by-regexp.md
index ea47a179af8..cb97ba5a03f 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/split-by-regexp.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/split-by-regexp.md
@@ -7,50 +7,162 @@
## Description
-Split the input string into an array of strings according to the specified regular expression.
+The SPLIT_BY_REGEXP function splits a string into an array of strings based on a specified regular expression pattern. Unlike SPLIT_BY_STRING, this function supports complex regular expression matching for more flexible splitting rules. It optionally supports a maximum split count limit, which is useful for structured text processing, data cleansing, and pattern matching.
## Syntax
```sql
-SPLIT_BY_REGEXP ( <str>, <pattern> [, <max_limit>] )
+SPLIT_BY_REGEXP(<str>, <pattern> [, <max_limit>])
```
## Parameters
-| Parameter | Description |
-|---------|------------------------------|
-| `<str>` | The string to be split |
-| `<pattern>` | Regular expression |
-| `<max_limit>` | Optional parameter, whether to limit the number of elements in the returned string array. The default is no limit |
+| Parameter | Description |
+|-----------|-------------|
+| `<str>` | The source string to be split. Type: VARCHAR |
+| `<pattern>` | Regular expression pattern used as the delimiter. Type: VARCHAR |
+| `<max_limit>` | Optional parameter, limits the maximum number of elements in the returned array. Type: INT |
## Return Value
-Return an array of strings split according to the specified regular expression. Special cases:
+Returns ARRAY<VARCHAR> type, representing an array of strings split by the regular expression.
-- If any of the parameters is NULL, NULL is returned.
+Splitting rules:
+- Uses regular expression pattern to match split points
+- Supports standard regular expression syntax
+- Empty string pattern will split the string into individual characters
+- If pattern doesn't match anything, returns single-element array containing the original string
+- max_limit restricts the maximum length of the result array
+
+Special cases:
+- If any parameter is NULL, returns NULL
+- If string is empty, returns single-element array containing empty string
+- If regular expression is empty string, splits by characters
+- If max_limit is 0 or negative, no limit is applied
+- Consecutive matches produce empty string elements
## Examples
+1. Empty pattern splits by characters
```sql
-SELECT split_by_regexp('abcde',"");
+SELECT SPLIT_BY_REGEXP('abcde', '');
```
-
```text
+------------------------------+
-| split_by_regexp('abcde', '') |
+| SPLIT_BY_REGEXP('abcde', '') |
+------------------------------+
| ["a", "b", "c", "d", "e"] |
+------------------------------+
```
+2. Digit pattern splitting
```sql
-select split_by_regexp('a12bc23de345f',"\\d+");
+SELECT SPLIT_BY_REGEXP('a12bc23de345f', '\\d+');
```
-
```text
+-----------------------------------------+
-| split_by_regexp('a12bc23de345f', '\d+') |
+| SPLIT_BY_REGEXP('a12bc23de345f', '\d+') |
+-----------------------------------------+
| ["a", "bc", "de", "f"] |
+-----------------------------------------+
```
+
+3. NULL value handling
+```sql
+SELECT SPLIT_BY_REGEXP(NULL, '\\d+'), SPLIT_BY_REGEXP('test', NULL);
+```
+```text
++--------------------------------+--------------------------------+
+| SPLIT_BY_REGEXP(NULL, '\d+') | SPLIT_BY_REGEXP('test', NULL) |
++--------------------------------+--------------------------------+
+| NULL | NULL |
++--------------------------------+--------------------------------+
+```
+
+4. Empty string handling
+```sql
+SELECT SPLIT_BY_REGEXP('', ','), SPLIT_BY_REGEXP('hello', 'xyz');
+```
+```text
++---------------------------+-------------------------------+
+| SPLIT_BY_REGEXP('', ',') | SPLIT_BY_REGEXP('hello', 'xyz') |
++---------------------------+-------------------------------+
+| [""] | ["hello"] |
++---------------------------+-------------------------------+
+```
+
+5. Using maximum limit parameter
+```sql
+SELECT SPLIT_BY_REGEXP('a,b,c,d,e', ',', 3), SPLIT_BY_REGEXP('1-2-3-4-5', '-', 2);
+```
+```text
++--------------------------------------+--------------------------------------+
+| SPLIT_BY_REGEXP('a,b,c,d,e', ',', 3) | SPLIT_BY_REGEXP('1-2-3-4-5', '-', 2) |
++--------------------------------------+--------------------------------------+
+| ["a", "b", "c,d,e"] | ["1", "2-3-4-5"] |
++--------------------------------------+--------------------------------------+
+```
+
+6. Whitespace pattern
+```sql
+SELECT SPLIT_BY_REGEXP('hello world test', '\\s+'), SPLIT_BY_REGEXP('a\tb\nc\rd', '\\s');
+```
+```text
++------------------------------------------+------------------------------------+
+| SPLIT_BY_REGEXP('hello world test', '\s+') | SPLIT_BY_REGEXP('a\tb\nc\rd', '\s') |
++------------------------------------------+------------------------------------+
+| ["hello", "world", "test"] | ["a", "b", "c", "d"] |
++------------------------------------------+------------------------------------+
+```
+
+7. Special characters and escaping
+```sql
+SELECT SPLIT_BY_REGEXP('a.b.c.d', '\\.'), SPLIT_BY_REGEXP('x(y)z[w]', '[\\(\\)\\[\\]]');
+```
+```text
++----------------------------------+--------------------------------------------+
+| SPLIT_BY_REGEXP('a.b.c.d', '\.') | SPLIT_BY_REGEXP('x(y)z[w]', '[\(\)\[\]]') |
++----------------------------------+--------------------------------------------+
+| ["a", "b", "c", "d"] | ["x", "y", "z", "w"] |
++----------------------------------+--------------------------------------------+
+```
+
+8. Word boundaries and complex patterns
+```sql
+SELECT SPLIT_BY_REGEXP('TheQuickBrownFox', '[A-Z]'), SPLIT_BY_REGEXP('user@example.com', '@|\\.');
+```
+```text
++------------------------------------------+-------------------------------------------+
+| SPLIT_BY_REGEXP('TheQuickBrownFox', '[A-Z]') | SPLIT_BY_REGEXP('user@example.com', '@|\.') |
++------------------------------------------+-------------------------------------------+
+| ["", "he", "uick", "rown", "ox"] | ["user", "example", "com"] |
++------------------------------------------+-------------------------------------------+
+```
+
+9. UTF-8 multi-byte characters
+```sql
+SELECT SPLIT_BY_REGEXP('ṭṛì→ḍḍumai→hello', '→'), SPLIT_BY_REGEXP('αβγδε', '[βδ]');
+```
+```text
++------------------------------------------+----------------------------------+
+| SPLIT_BY_REGEXP('ṭṛì→ḍḍumai→hello', '→') | SPLIT_BY_REGEXP('αβγδε', '[βδ]') |
++------------------------------------------+----------------------------------+
+| ["ṭṛì", "ḍḍumai", "hello"] | ["α", "γ", "ε"] |
++------------------------------------------+----------------------------------+
+```
+
+10. Consecutive matches and empty elements
+```sql
+SELECT SPLIT_BY_REGEXP('a,,b,c', ','), SPLIT_BY_REGEXP('123abc456def', '[a-z]+');
+```
+```text
++-------------------------------+---------------------------------------+
+| SPLIT_BY_REGEXP('a,,b,c', ',') | SPLIT_BY_REGEXP('123abc456def', '[a-z]+') |
++-------------------------------+---------------------------------------+
+| ["a", "", "b", "c"] | ["123", "456", ""] |
++-------------------------------+---------------------------------------+
+```
+
+### Keywords
+
+ SPLIT_BY_REGEXP, SPLIT, REGEXP
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/split-by-string.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/split-by-string.md
index bb4485474df..c8af495fd6b 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/split-by-string.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/split-by-string.md
@@ -7,50 +7,159 @@
## Description
-Split the input string into a string array according to the specified string.
+The SPLIT_BY_STRING function splits an input string into an array of strings based on a specified delimiter string. This function supports multi-character delimiters and may differ from similar functions in other databases in handling empty strings.
## Syntax
```sql
-SPLIT_BY_STRING ( <str>, <separator> )
+SPLIT_BY_STRING(<str>, <separator>)
```
## Parameters
-| Parameter | Description |
-|---------------|--------------------------------|
-| `<str>` | The string to be split. |
-| `<separator>` | The string used for splitting. |
+| Parameter | Description |
+|-----------|-------------|
+| `<str>` | The source string to be split. Type: VARCHAR |
+| `<separator>` | The delimiter string used for splitting. Type: VARCHAR |
## Return Value
-Returns a string array split according to the specified string. Special cases:
+Returns ARRAY<VARCHAR> type, containing an array of strings split by the delimiter.
-- If any of the parameters is NULL, NULL is returned.
-- When `<separator>` is an empty string, `<str>` will be split to byte sequence.
+Splitting rules:
+- Splits at each occurrence of separator in str
+- Consecutive separators produce empty string elements
+- Separators at the beginning or end of the string produce empty string elements
+
+Special cases:
+- If any parameter is NULL, returns NULL
+- If str is empty string, returns array with one empty string [""]
+- If separator is empty string, str is split by characters (each character becomes an array element)
+- If separator doesn't exist in str, returns array containing the original string
+- If str contains only separators, returns corresponding number of empty strings based on separator count
## Examples
+1. Basic string splitting
```sql
-SELECT split_by_string('hello','l');
+SELECT SPLIT_BY_STRING('hello', 'l');
```
-
```text
+-------------------------------+
-| split_by_string('hello', 'l') |
+| SPLIT_BY_STRING('hello', 'l') |
+-------------------------------+
| ["he", "", "o"] |
+-------------------------------+
```
+2. Empty separator (split by characters)
```sql
-SELECT split_by_string('hello','');
+SELECT SPLIT_BY_STRING('hello', '');
```
-
```text
+------------------------------+
-| split_by_string('hello', '') |
+| SPLIT_BY_STRING('hello', '') |
+------------------------------+
| ["h", "e", "l", "l", "o"] |
+------------------------------+
```
+
+3. Multi-character separator
+```sql
+SELECT SPLIT_BY_STRING('apple::banana::cherry', '::');
+```
+```text
++------------------------------------------------+
+| SPLIT_BY_STRING('apple::banana::cherry', '::') |
++------------------------------------------------+
+| ["apple", "banana", "cherry"] |
++------------------------------------------------+
+```
+
+4. NULL value handling
+```sql
+SELECT SPLIT_BY_STRING(NULL, ','), SPLIT_BY_STRING('hello', NULL);
+```
+```text
++-----------------------------+----------------------------------+
+| SPLIT_BY_STRING(NULL, ',') | SPLIT_BY_STRING('hello', NULL) |
++-----------------------------+----------------------------------+
+| NULL | NULL |
++-----------------------------+----------------------------------+
+```
+
+5. Empty string handling
+```sql
+SELECT SPLIT_BY_STRING('', ','), SPLIT_BY_STRING('hello', 'xyz');
+```
+```text
++---------------------------+----------------------------------+
+| SPLIT_BY_STRING('', ',') | SPLIT_BY_STRING('hello', 'xyz') |
++---------------------------+----------------------------------+
+| [""] | ["hello"] |
++---------------------------+----------------------------------+
+```
+
+6. Consecutive separators
+```sql
+SELECT SPLIT_BY_STRING('a,,b,c', ',');
+```
+```text
++-------------------------------+
+| SPLIT_BY_STRING('a,,b,c', ',') |
++-------------------------------+
+| ["a", "", "b", "c"] |
++-------------------------------+
+```
+
+7. Separators at beginning and end
+```sql
+SELECT SPLIT_BY_STRING(',a,b,', ',');
+```
+```text
++------------------------------+
+| SPLIT_BY_STRING(',a,b,', ',') |
++------------------------------+
+| ["", "a", "b", ""] |
++------------------------------+
+```
+
+8. Only contains separators
+```sql
+SELECT SPLIT_BY_STRING('|||', '|');
+```
+```text
++----------------------------+
+| SPLIT_BY_STRING('|||', '|') |
++----------------------------+
+| ["", "", "", ""] |
++----------------------------+
+```
+
+9. UTF-8 character splitting
+```sql
+SELECT SPLIT_BY_STRING('ṭṛì ḍḍumai ṭṛì', ' ');
+```
+```text
++--------------------------------------+
+| SPLIT_BY_STRING('ṭṛì ḍḍumai ṭṛì', ' ') |
++--------------------------------------+
+| ["ṭṛì", "ḍḍumai", "ṭṛì"] |
++--------------------------------------+
+```
+
+10. Non-existent separator
+```sql
+SELECT SPLIT_BY_STRING('hello world', 'xyz');
+```
+```text
++--------------------------------------+
+| SPLIT_BY_STRING('hello world', 'xyz') |
++--------------------------------------+
+| ["hello world"] |
++--------------------------------------+
+```
+
+### Keywords
+
+ SPLIT_BY_STRING, SPLIT
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/split-part.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/split-part.md
index 577d2e0ffa6..267b3e869ef 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/split-part.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/split-part.md
@@ -32,26 +32,126 @@ Returns the specified part of the string split according to the delimiter. Speci
## Examples
+1. Basic string splitting
```sql
-select split_part("hello world", " ", 1);
+SELECT SPLIT_PART('hello world', ' ', 1);
```
-
```text
+----------------------------------+
-| split_part('hello world', ' ', 1) |
+| SPLIT_PART('hello world', ' ', 1) |
+----------------------------------+
| hello |
+----------------------------------+
```
+2. Get second part
```sql
-SELECT split_part('apple,banana,cherry', ',', 0);
+SELECT SPLIT_PART('apple,banana,cherry', ',', 2);
+```
+```text
++-------------------------------------------+
+| SPLIT_PART('apple,banana,cherry', ',', 2) |
++-------------------------------------------+
+| banana |
++-------------------------------------------+
```
+3. Index is 0 (returns NULL)
+```sql
+SELECT SPLIT_PART('apple,banana,cherry', ',', 0);
+```
```text
+-------------------------------------------+
-| split_part('apple,banana,cherry', ',', 0) |
+| SPLIT_PART('apple,banana,cherry', ',', 0) |
+-------------------------------------------+
| NULL |
+-------------------------------------------+
```
+
+4. Negative index (count from end)
+```sql
+SELECT SPLIT_PART('apple,banana,cherry', ',', -1), SPLIT_PART('apple,banana,cherry', ',', -2);
+```
+```text
++--------------------------------------------+--------------------------------------------+
+| SPLIT_PART('apple,banana,cherry', ',', -1) | SPLIT_PART('apple,banana,cherry', ',', -2) |
++--------------------------------------------+--------------------------------------------+
+| cherry | banana |
++--------------------------------------------+--------------------------------------------+
+```
+
+5. Index out of range
+```sql
+SELECT SPLIT_PART('apple,banana', ',', 5), SPLIT_PART('apple,banana', ',', -5);
+```
+```text
++-----------------------------------+------------------------------------+
+| SPLIT_PART('apple,banana', ',', 5) | SPLIT_PART('apple,banana', ',', -5) |
++-----------------------------------+------------------------------------+
+| | |
++-----------------------------------+------------------------------------+
+```
+
+6. NULL value handling
+```sql
+SELECT SPLIT_PART(NULL, ',', 1), SPLIT_PART('test', NULL, 1), SPLIT_PART('test', ',', NULL);
+```
+```text
++---------------------------+-----------------------------+-------------------------------+
+| SPLIT_PART(NULL, ',', 1) | SPLIT_PART('test', NULL, 1) | SPLIT_PART('test', ',', NULL) |
++---------------------------+-----------------------------+-------------------------------+
+| NULL | NULL | NULL |
++---------------------------+-----------------------------+-------------------------------+
+```
+
+7. Empty string handling
+```sql
+SELECT SPLIT_PART('', ',', 1), SPLIT_PART('test', '', 2);
+```
+```text
++------------------------+---------------------------+
+| SPLIT_PART('', ',', 1) | SPLIT_PART('test', '', 2) |
++------------------------+---------------------------+
+| NULL | |
++------------------------+---------------------------+
+```
+
+8. Separator doesn't exist
+```sql
+SELECT SPLIT_PART('hello world', '|', 1), SPLIT_PART('hello world', '|', 2);
+```
+```text
++-----------------------------------+-----------------------------------+
+| SPLIT_PART('hello world', '|', 1) | SPLIT_PART('hello world', '|', 2) |
++-----------------------------------+-----------------------------------+
+| NULL | NULL |
++-----------------------------------+-----------------------------------+
+```
+
+9. Consecutive separators
+```sql
+SELECT SPLIT_PART('a,,c', ',', 1), SPLIT_PART('a,,c', ',', 2), SPLIT_PART('a,,c', ',', 3);
+```
+```text
++----------------------------+----------------------------+----------------------------+
+| SPLIT_PART('a,,c', ',', 1) | SPLIT_PART('a,,c', ',', 2) | SPLIT_PART('a,,c', ',', 3) |
++----------------------------+----------------------------+----------------------------+
+| a | | c |
++----------------------------+----------------------------+----------------------------+
+```
+
+10. UTF-8 character handling
+```sql
+SELECT SPLIT_PART('ṭṛì ḍḍumai ṭṛì', ' ', 2);
+```
+```text
++--------------------------------------+
+| SPLIT_PART('ṭṛì ḍḍumai ṭṛì', ' ', 2) |
++--------------------------------------+
+| ḍḍumai |
++--------------------------------------+
+```
+
+### Keywords
+
+ SPLIT_PART, SPLIT
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/starts-with.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/starts-with.md
index 80d5ae2c169..13b4bc7db13 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/starts-with.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/starts-with.md
@@ -5,9 +5,10 @@
}
---
+
## Description
-The STARTS_WITH function checks if a string starts with a specified prefix. Returns true if the string starts with the specified prefix; otherwise returns false.
+The STARTS_WITH function checks if a string starts with a specified prefix. This is a boolean function that performs exact prefix matching and is case-sensitive.
## Syntax
@@ -16,40 +17,149 @@ STARTS_WITH(<str>, <prefix>)
```
## Parameters
-| Parameter | Description |
+| Parameter | Description |
| --------- | ----------------------------------------- |
-| `<str>` | The string to check. Type: VARCHAR |
+| `<str>` | The main string to check. Type: VARCHAR |
| `<prefix>` | The prefix string to match. Type: VARCHAR |
## Return Value
-Returns BOOLEAN type.
+Returns BOOLEAN type (displayed as TINYINT in Doris, 1 for true, 0 for false).
+
+Matching rules:
+- Exact prefix match, case-sensitive
+- Empty prefix matches any string (returns true)
+- Supports correct matching of UTF-8 multi-byte characters
+- Prefix length cannot exceed main string length (unless prefix is empty)
Special cases:
- Returns NULL if any argument is NULL
+- Returns true if prefix is empty string (any string starts with empty string)
+- Returns false if main string is empty but prefix is not
+- Returns true if both are empty strings
## Examples
-1. Successful match
+1. Basic prefix matching
+```sql
+SELECT STARTS_WITH('hello world', 'hello'), STARTS_WITH('hello world', 'world');
+```
+```text
++-------------------------------------+-------------------------------------+
+| STARTS_WITH('hello world', 'hello') | STARTS_WITH('hello world', 'world') |
++-------------------------------------+-------------------------------------+
+| 1 | 0 |
++-------------------------------------+-------------------------------------+
+```
+
+2. Case sensitivity
+```sql
+SELECT STARTS_WITH('Hello World', 'hello'), STARTS_WITH('Hello World', 'Hello');
+```
+```text
++-------------------------------------+-------------------------------------+
+| STARTS_WITH('Hello World', 'hello') | STARTS_WITH('Hello World', 'Hello') |
++-------------------------------------+-------------------------------------+
+| 0 | 1 |
++-------------------------------------+-------------------------------------+
+```
+
+3. NULL value handling
```sql
-SELECT starts_with('hello world', 'hello');
+SELECT STARTS_WITH(NULL, 'test'), STARTS_WITH('test', NULL);
```
```text
-+-------------------------------------+
-| starts_with('hello world', 'hello') |
-+-------------------------------------+
-| 1 |
-+-------------------------------------+
++----------------------------+----------------------------+
+| STARTS_WITH(NULL, 'test') | STARTS_WITH('test', NULL) |
++----------------------------+----------------------------+
+| NULL | NULL |
++----------------------------+----------------------------+
```
-2. Failed match
+4. Empty string handling
```sql
-SELECT starts_with('hello world', 'world');
+SELECT STARTS_WITH('hello', ''), STARTS_WITH('', 'world');
```
```text
-+-------------------------------------+
-| starts_with('hello world', 'world') |
-+-------------------------------------+
-| 0 |
-+-------------------------------------+
-```
\ No newline at end of file
++---------------------------+----------------------------+
+| STARTS_WITH('hello', '') | STARTS_WITH('', 'world') |
++---------------------------+----------------------------+
+| 1 | 0 |
++---------------------------+----------------------------+
+```
+
+5. Complete string match
+```sql
+SELECT STARTS_WITH('test', 'test'), STARTS_WITH('test', 'testing');
+```
+```text
++-----------------------------+--------------------------------+
+| STARTS_WITH('test', 'test') | STARTS_WITH('test', 'testing') |
++-----------------------------+--------------------------------+
+| 1 | 0 |
++-----------------------------+--------------------------------+
+```
+
+6. File path checking
+```sql
+SELECT STARTS_WITH('/home/user/file.txt', '/home'), STARTS_WITH('C:\\Windows\\file.txt', 'C:\\');
+```
+```text
++--------------------------------------------+------------------------------------------------+
+| STARTS_WITH('/home/user/file.txt', '/home') | STARTS_WITH('C:\\Windows\\file.txt', 'C:\\') |
++--------------------------------------------+------------------------------------------------+
+| 1 | 1 |
++--------------------------------------------+------------------------------------------------+
+```
+
+7. UTF-8 multi-byte characters
+```sql
+SELECT STARTS_WITH('ṭṛì ḍḍumai hello', 'ṭṛì'), STARTS_WITH('ṭṛì ḍḍumai hello', 'ḍḍumai');
+```
+```text
++------------------------------------------+---------------------------------------------+
+| STARTS_WITH('ṭṛì ḍḍumai hello', 'ṭṛì') | STARTS_WITH('ṭṛì ḍḍumai hello', 'ḍḍumai') |
++------------------------------------------+---------------------------------------------+
+| 1 | 0 |
++------------------------------------------+---------------------------------------------+
+```
+
+8. URL and protocol checking
+```sql
+SELECT STARTS_WITH('https://example.com', 'https://'), STARTS_WITH('ftp://server.com', 'http://');
+```
+```text
++----------------------------------------------+---------------------------------------------+
+| STARTS_WITH('https://example.com', 'https://') | STARTS_WITH('ftp://server.com', 'http://') |
++----------------------------------------------+---------------------------------------------+
+| 1 | 0 |
++----------------------------------------------+---------------------------------------------+
+```
+
+9. Numeric string prefix
+```sql
+SELECT STARTS_WITH('123456789', '123'), STARTS_WITH('987654321', '123');
+```
+```text
++----------------------------------+----------------------------------+
+| STARTS_WITH('123456789', '123') | STARTS_WITH('987654321', '123') |
++----------------------------------+----------------------------------+
+| 1 | 0 |
++----------------------------------+----------------------------------+
+```
+
+10. Special characters and symbols
+```sql
+SELECT STARTS_WITH('@username', '@'), STARTS_WITH('#hashtag', '#');
+```
+```text
++-------------------------------+--------------------------------+
+| STARTS_WITH('@username', '@') | STARTS_WITH('#hashtag', '#') |
++-------------------------------+--------------------------------+
+| 1 | 1 |
++-------------------------------+--------------------------------+
+```
+
+### Keywords
+
+ STARTS_WITH
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/strcmp.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/strcmp.md
index 17f621200b4..4aadce878bf 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/strcmp.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/strcmp.md
@@ -17,13 +17,13 @@ STRCMP(<str0>, <str1>)
## Parameters
| Parameter | Description |
-| -- | -- |
+| --------- | ----------------------------------------- |
| `<str0>` | The first string to compare. Type: VARCHAR |
| `<str1>` | The second string to compare. Type: VARCHAR |
## Return Value
-Returns a TINYINT value indicating the comparison result:
+Returns TINYINT type, indicating the comparison result:
- Returns 0: if str0 equals str1
- Returns 1: if str0 is lexicographically greater than str1
- Returns -1: if str0 is lexicographically less than str1
@@ -33,7 +33,7 @@ Special cases:
## Examples
-1. Comparing identical strings
+1. Identical string comparison
```sql
SELECT strcmp('test', 'test');
```
@@ -67,4 +67,8 @@ SELECT strcmp('test', 'test1');
+-------------------------+
| -1 |
+-------------------------+
-```
\ No newline at end of file
+```
+
+### Keywords
+
+ STRCMP
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/strleft.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/strleft.md
index 8a215c8aff5..010a8187885 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/strleft.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/strleft.md
@@ -36,50 +36,102 @@ Special cases:
## Examples
-1. Basic usage
+1. Basic left extraction
```sql
-SELECT strleft('Hello doris', 5);
+SELECT STRLEFT('Hello doris', 5), LEFT('Hello doris', 5);
```
```text
-+---------------------------+
-| strleft('Hello doris', 5) |
-+---------------------------+
-| Hello |
-+---------------------------+
++---------------------------+----------------------+
+| STRLEFT('Hello doris', 5) | LEFT('Hello doris', 5) |
++---------------------------+----------------------+
+| Hello | Hello |
++---------------------------+----------------------+
```
-2. Handling negative length
+2. Different extraction lengths
```sql
-SELECT strleft('Hello doris', -5);
+SELECT STRLEFT('Hello World', 3), STRLEFT('Hello World', 8);
```
```text
-+----------------------------+
-| strleft('Hello doris', -5) |
-+----------------------------+
-| |
-+----------------------------+
++----------------------------+----------------------------+
+| STRLEFT('Hello World', 3) | STRLEFT('Hello World', 8) |
++----------------------------+----------------------------+
+| Hel | Hello Wo |
++----------------------------+----------------------------+
```
-3. Handling NULL parameter
+3. NULL value handling
```sql
-SELECT strleft('Hello doris', NULL);
+SELECT STRLEFT(NULL, 5), STRLEFT('Hello doris', NULL);
```
```text
-+------------------------------+
-| strleft('Hello doris', NULL) |
-+------------------------------+
-| NULL |
-+------------------------------+
++------------------+------------------------------+
+| STRLEFT(NULL, 5) | STRLEFT('Hello doris', NULL) |
++------------------+------------------------------+
+| NULL | NULL |
++------------------+------------------------------+
```
-4. Handling NULL string
+4. Empty string and zero length
```sql
-SELECT strleft(NULL, 3);
+SELECT STRLEFT('', 5), STRLEFT('Hello World', 0);
```
```text
-+------------------+
-| strleft(NULL, 3) |
-+------------------+
-| NULL |
-+------------------+
-```
\ No newline at end of file
++------------------+----------------------------+
+| STRLEFT('', 5) | STRLEFT('Hello World', 0) |
++------------------+----------------------------+
+| | |
++------------------+----------------------------+
+```
+
+5. Negative length handling
+```sql
+SELECT STRLEFT('Hello doris', -5), STRLEFT('Hello doris', -1);
+```
+```text
++-----------------------------+----------------------------+
+| STRLEFT('Hello doris', -5) | STRLEFT('Hello doris', -1) |
++-----------------------------+----------------------------+
+| | |
++-----------------------------+----------------------------+
+```
+
+6. Length exceeds string length
+```sql
+SELECT STRLEFT('ABC', 10), STRLEFT('short', 20);
+```
+```text
++--------------------+----------------------+
+| STRLEFT('ABC', 10) | STRLEFT('short', 20) |
++--------------------+----------------------+
+| ABC | short |
++--------------------+----------------------+
+```
+
+7. UTF-8 multi-byte characters
+```sql
+SELECT STRLEFT('ṭṛì ḍḍumai hello', 3), STRLEFT('ṭṛì ḍḍumai hello', 7);
+```
+```text
++---------------------------------+----------------------------------+
+| STRLEFT('ṭṛì ḍḍumai hello', 3) | STRLEFT('ṭṛì ḍḍumai hello', 7) |
++---------------------------------+----------------------------------+
+| ṭṛì | ṭṛì ḍḍu |
++---------------------------------+----------------------------------+
+```
+
+8. Number and ID prefix
+```sql
+SELECT STRLEFT('ID123456789', 5), STRLEFT('USER_987654321', 5);
+```
+```text
++----------------------------+------------------------------+
+| STRLEFT('ID123456789', 5) | STRLEFT('USER_987654321', 5) |
++----------------------------+------------------------------+
+| ID123 | USER_ |
++----------------------------+------------------------------+
+```
+
+### Keywords
+
+ STRLEFT, LEFT
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/strright.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/strright.md
index 4a8ae81b384..a1b4c966596 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/strright.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/strright.md
@@ -36,50 +36,114 @@ Special cases:
## Examples
-1. Basic usage
+1. Basic right extraction
```sql
-SELECT strright('Hello doris', 5);
+SELECT STRRIGHT('Hello doris', 5), RIGHT('Hello doris', 5);
```
```text
-+----------------------------+
-| strright('Hello doris', 5) |
-+----------------------------+
-| doris |
-+----------------------------+
++----------------------------+------------------------+
+| STRRIGHT('Hello doris', 5) | RIGHT('Hello doris', 5) |
++----------------------------+------------------------+
+| doris | doris |
++----------------------------+------------------------+
```
-2. Handling negative length
+2. Different extraction lengths
```sql
-SELECT strright('Hello doris', -7);
+SELECT STRRIGHT('Hello World', 3), STRRIGHT('Hello World', 8);
```
```text
-+-----------------------------+
-| strright('Hello doris', -7) |
-+-----------------------------+
-| doris |
-+-----------------------------+
++-----------------------------+-----------------------------+
+| STRRIGHT('Hello World', 3) | STRRIGHT('Hello World', 8) |
++-----------------------------+-----------------------------+
+| rld | lo World |
++-----------------------------+-----------------------------+
```
-3. Handling NULL parameter
+3. NULL value handling
```sql
-SELECT strright('Hello doris', NULL);
+SELECT STRRIGHT(NULL, 5), STRRIGHT('Hello doris', NULL);
```
```text
-+-------------------------------+
-| strright('Hello doris', NULL) |
-+-------------------------------+
-| NULL |
-+-------------------------------+
++-------------------+-------------------------------+
+| STRRIGHT(NULL, 5) | STRRIGHT('Hello doris', NULL) |
++-------------------+-------------------------------+
+| NULL | NULL |
++-------------------+-------------------------------+
```
-4. Handling NULL string
+4. Empty string and zero length
```sql
-SELECT strright(NULL, 5);
+SELECT STRRIGHT('', 5), STRRIGHT('Hello World', 0);
```
```text
-+-------------------+
-| strright(NULL, 5) |
-+-------------------+
-| NULL |
-+-------------------+
-```
\ No newline at end of file
++-------------------+-----------------------------+
+| STRRIGHT('', 5) | STRRIGHT('Hello World', 0) |
++-------------------+-----------------------------+
+| | |
++-------------------+-----------------------------+
+```
+
+5. Negative length handling
+```sql
+SELECT STRRIGHT('Hello doris', -7), STRRIGHT('Hello doris', -5);
+```
+```text
++-----------------------------+-----------------------------+
+| STRRIGHT('Hello doris', -7) | STRRIGHT('Hello doris', -5) |
++-----------------------------+-----------------------------+
+| doris | o doris |
++-----------------------------+-----------------------------+
+```
+
+6. Length exceeds string length
+```sql
+SELECT STRRIGHT('ABC', 10), STRRIGHT('short', 20);
+```
+```text
++---------------------+-----------------------+
+| STRRIGHT('ABC', 10) | STRRIGHT('short', 20) |
++---------------------+-----------------------+
+| ABC | short |
++---------------------+-----------------------+
+```
+
+7. UTF-8 multi-byte characters
+```sql
+SELECT STRRIGHT('ṭṛì ḍḍumai hello', 5), STRRIGHT('ṭṛì ḍḍumai hello', 11);
+```
+```text
++----------------------------------+-----------------------------------+
+| STRRIGHT('ṭṛì ḍḍumai hello', 5) | STRRIGHT('ṭṛì ḍḍumai hello', 11) |
++----------------------------------+-----------------------------------+
+| hello | ḍumai hello |
++----------------------------------+-----------------------------------+
+```
+
+8. Numeric string handling
+```sql
+SELECT STRRIGHT('123456789', 3), STRRIGHT('ID_987654321', 6);
+```
+```text
++----------------------------+-------------------------------+
+| STRRIGHT('123456789', 3) | STRRIGHT('ID_987654321', 6) |
++----------------------------+-------------------------------+
+| 789 | 654321 |
++----------------------------+-------------------------------+
+```
+
+9. Email domain extraction
+```sql
+SELECT STRRIGHT('user@example.com', 11), STRRIGHT('admin@company.org.cn', 14);
+```
+```text
++----------------------------------+--------------------------------------+
+| STRRIGHT('user@example.com', 11) | STRRIGHT('admin@company.org.cn', 14) |
++----------------------------------+--------------------------------------+
+| example.com | company.org.cn |
++----------------------------------+--------------------------------------+
+```
+
+### Keywords
+
+ STRRIGHT, RIGHT
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/sub-replace.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/sub-replace.md
index 29d97a0c6a4..f4d7cb3e204 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/sub-replace.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/sub-replace.md
@@ -30,26 +30,90 @@ Returns the string after replacement.
## Examples
+1. Basic usage: specify position and length replacement
```sql
-select sub_replace("this is origin str", "NEW-STR", 1);
+SELECT sub_replace('doris', '***', 1, 2);
+```
+```text
++-----------------------------------+
+| sub_replace('doris', '***', 1, 2) |
++-----------------------------------+
+| d***is |
++-----------------------------------+
```
+2. Using default length replacement
+```sql
+SELECT sub_replace('hello', 'Hi', 0);
+```
```text
-+-------------------------------------------------+
-| sub_replace('this is origin str', 'NEW-STR', 1) |
-+-------------------------------------------------+
-| tNEW-STRorigin str |
-+-------------------------------------------------+
++--------------------------------+
+| sub_replace('hello', 'Hi', 0) |
++--------------------------------+
+| Hillo |
++--------------------------------+
```
+3. Negative parameter returns NULL
```sql
-select sub_replace("doris","***", 1, 2);
+SELECT sub_replace('hello', 'Hi', -1, 2);
+```
+```text
++------------------------------------+
+| sub_replace('hello', 'Hi', -1, 2) |
++------------------------------------+
+| NULL |
++------------------------------------+
```
+4. NULL value handling
+```sql
+SELECT sub_replace(NULL, 'new', 0, 3);
+```
```text
-+-----------------------------------+
-| sub_replace('doris', '***', 1, 2) |
-+-----------------------------------+
-| d***is |
-+-----------------------------------+
++-------------------------------------+
+| sub_replace(NULL, 'new', 0, 3) |
++-------------------------------------+
+| NULL |
++-------------------------------------+
```
+
+5. UTF-8 string
+```sql
+SELECT sub_replace('doris', 'ṛìḍḍ', 1, 2);
+```
+```text
++-------------------------------------------+
+| sub_replace('doris', 'ṛìḍḍ', 1, 2) |
++-------------------------------------------+
+| dṛìḍḍis |
++-------------------------------------------+
+```
+
+6. Start position exceeds string length
+```sql
+SELECT sub_replace('hello', 'Hi', 9, 2);
+```
+```text
++----------------------------------+
+| sub_replace('hello', 'Hi', 9, 2) |
++----------------------------------+
+| NULL |
++----------------------------------+
+```
+
+7. Specified replacement length exceeds remaining string length
+```sql
+SELECT sub_replace('hello', 'Hi', 1, 9);
+```
+```text
++----------------------------------+
+| sub_replace('hello', 'Hi', 1, 9) |
++----------------------------------+
+| hHi |
++----------------------------------+
+```
+
+### Keywords
+
+ SUB_REPLACE, REPLACE
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/substring-index.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/substring-index.md
index d2aab370856..2b0010496d9 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/substring-index.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/substring-index.md
@@ -7,7 +7,7 @@
## Description
-The SUBSTRING_INDEX function is used to extract a substring from a string based on a specified delimiter and occurrence count. This function supports counting from either left or right.
+The SUBSTRING_INDEX function is used to extract a portion of a string based on a specified delimiter. By specifying the number of delimiter occurrences, extraction can be performed from either the left or right side.
## Syntax
@@ -16,68 +16,139 @@ SUBSTRING_INDEX(<content>, <delimiter>, <field>)
```
## Parameters
-| Parameter | Description |
+| Parameter | Description |
| --------- | --------------------------------------------------------------------------------------------------------------- |
-| `<content>` | The string to be extracted from. Type: VARCHAR |
-| `<delimiter>` | The delimiter string, case-sensitive and multi-byte safe. Type: VARCHAR |
-| `<field>` | Number of delimiter occurrences. Positive numbers count from left, negative numbers count from right. Type: INT |
+| `<content>` | The source string to extract from. Type: VARCHAR |
+| `<delimiter>` | The delimiter string, case-sensitive and supports multi-byte characters. Type: VARCHAR |
+| `<field>` | Number of delimiter occurrences. Positive counts from left, negative counts from right, 0 returns empty string. Type: INT |
## Return Value
Returns VARCHAR type, representing the extracted substring.
+Extraction rules:
+- When field > 0: returns content before the field-th delimiter from the left
+- When field < 0: returns content after the |field|-th delimiter from the right
+- When field = 0: returns empty string (returns NULL when content is NULL)
+- Case-sensitive exact delimiter matching
+
Special cases:
-- If field > 0, returns the substring before the field-th delimiter from the left
-- If field < 0, returns the substring after the |field|-th delimiter from the right
-- If field = 0, returns empty string when content is not NULL, returns NULL when content is NULL
- If any parameter is NULL, returns NULL
+- If delimiter doesn't exist in string, returns original string
+- If specified count exceeds actual delimiter occurrences, returns maximum extractable portion
+- If delimiter is empty string, returns empty string
+- If source string is empty, returns empty string
## Examples
-1. Extract content before the first space from the left
+1. Basic left extraction
+```sql
+SELECT SUBSTRING_INDEX('hello world', ' ', 1), SUBSTRING_INDEX('one,two,three', ',', 2);
+```
+```text
++----------------------------------------+------------------------------------------+
+| SUBSTRING_INDEX('hello world', ' ', 1) | SUBSTRING_INDEX('one,two,three', ',', 2) |
++----------------------------------------+------------------------------------------+
+| hello | one,two |
++----------------------------------------+------------------------------------------+
+```
+
+2. Right extraction (negative count)
```sql
-SELECT substring_index('hello world', ' ', 1);
+SELECT SUBSTRING_INDEX('hello world', ' ', -1), SUBSTRING_INDEX('one,two,three', ',', -1);
```
```text
-+----------------------------------------+
-| substring_index('hello world', ' ', 1) |
-+----------------------------------------+
-| hello |
-+----------------------------------------+
++-----------------------------------------+-------------------------------------------+
+| SUBSTRING_INDEX('hello world', ' ', -1) | SUBSTRING_INDEX('one,two,three', ',', -1) |
++-----------------------------------------+-------------------------------------------+
+| world | three |
++-----------------------------------------+-------------------------------------------+
```
-2. Extract all content from the left (delimiter count greater than actual occurrences)
+3. NULL value handling
```sql
-SELECT substring_index('hello world', ' ', 2);
+SELECT SUBSTRING_INDEX(NULL, ',', 1), SUBSTRING_INDEX('test', NULL, 1);
```
```text
-+----------------------------------------+
-| substring_index('hello world', ' ', 2) |
-+----------------------------------------+
-| hello world |
-+----------------------------------------+
++--------------------------------+------------------------------------+
+| SUBSTRING_INDEX(NULL, ',', 1) | SUBSTRING_INDEX('test', NULL, 1) |
++--------------------------------+------------------------------------+
+| NULL | NULL |
++--------------------------------+------------------------------------+
```
-3. Extract content after the last space from the right
+4. Zero count handling
```sql
-SELECT substring_index('hello world', ' ', -1);
+SELECT SUBSTRING_INDEX('hello world', ' ', 0), SUBSTRING_INDEX('a,b,c', ',', 0);
```
```text
-+-----------------------------------------+
-| substring_index('hello world', ' ', -1) |
-+-----------------------------------------+
-| world |
-+-----------------------------------------+
++----------------------------------------+----------------------------------+
+| SUBSTRING_INDEX('hello world', ' ', 0) | SUBSTRING_INDEX('a,b,c', ',', 0) |
++----------------------------------------+----------------------------------+
+| | |
++----------------------------------------+----------------------------------+
```
-4. Case when field is 0
+5. Delimiter doesn't exist
```sql
-SELECT substring_index('hello world', ' ', 0);
+SELECT SUBSTRING_INDEX('hello world', ',', 1), SUBSTRING_INDEX('no-delimiter', '|', -1);
```
```text
-+----------------------------------------+
-| substring_index('hello world', ' ', 0) |
-+----------------------------------------+
-| |
-+----------------------------------------+
-```
\ No newline at end of file
++----------------------------------------+------------------------------------------+
+| SUBSTRING_INDEX('hello world', ',', 1) | SUBSTRING_INDEX('no-delimiter', '|', -1) |
++----------------------------------------+------------------------------------------+
+| hello world | no-delimiter |
++----------------------------------------+------------------------------------------+
+```
+
+6. Count exceeds delimiter occurrences
+```sql
+SELECT SUBSTRING_INDEX('a,b,c', ',', 5), SUBSTRING_INDEX('a,b,c', ',', -5);
+```
+```text
++----------------------------------+-----------------------------------+
+| SUBSTRING_INDEX('a,b,c', ',', 5) | SUBSTRING_INDEX('a,b,c', ',', -5) |
++----------------------------------+-----------------------------------+
+| a,b,c | a,b,c |
++----------------------------------+-----------------------------------+
+```
+
+7. UTF-8 multi-byte character delimiter
+```sql
+SELECT SUBSTRING_INDEX('ṭṛì→ḍḍumai→hello', '→', 1), SUBSTRING_INDEX('ṭṛì→ḍḍumai→hello', '→', -1);
+```
+```text
++-----------------------------------------------+------------------------------------------------+
+| SUBSTRING_INDEX('ṭṛì→ḍḍumai→hello', '→', 1) | SUBSTRING_INDEX('ṭṛì→ḍḍumai→hello', '→', -1) |
++-----------------------------------------------+------------------------------------------------+
+| ṭṛì | hello |
++-----------------------------------------------+------------------------------------------------+
+```
+
+8. Multi-character delimiter
+```sql
+SELECT SUBSTRING_INDEX('data::field::value', '::', 2), SUBSTRING_INDEX('data::field::value', '::', -1);
+```
+```text
++---------------------------------------------+----------------------------------------------+
+| SUBSTRING_INDEX('data::field::value', '::', 2) | SUBSTRING_INDEX('data::field::value', '::', -1) |
++---------------------------------------------+----------------------------------------------+
+| data::field | value |
++---------------------------------------------+----------------------------------------------+
+```
+
+9. Empty source string
+```sql
+SELECT SUBSTRING_INDEX('', ' ', 1);
+```
+```text
++-----------------------------+
+| SUBSTRING_INDEX('', ' ', 1) |
++-----------------------------+
+| |
++-----------------------------+
+```
+
+### Keywords
+
+ SUBSTRING_INDEX, SUBSTRING
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/substring.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/substring.md
index 5f5cf6a987c..ac73a20e92b 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/substring.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/substring.md
@@ -137,4 +137,32 @@ SELECT MID(NULL, 2);
+--------------+
| NULL |
+--------------+
-```
\ No newline at end of file
+```
+
+9. Using alias SUBSTR
+```sql
+SELECT SUBSTR('Hello World', 7, 5);
+```
+```text
++------------------------------+
+| SUBSTR('Hello World', 7, 5) |
++------------------------------+
+| World |
++------------------------------+
+```
+
+10. UTF-8 multi-byte characters
+```sql
+SELECT SUBSTRING('ṭṛì ḍḍumai hello', 5, 6);
+```
+```text
++--------------------------------------+
+| SUBSTRING('ṭṛì ḍḍumai hello', 5, 6) |
++--------------------------------------+
+| ḍḍumai |
++--------------------------------------+
+```
+
+### Keywords
+
+ SUBSTRING, SUBSTR, MID
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/to-base64.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/to-base64.md
index e4f69a562a7..8128b6ebc83 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/to-base64.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/to-base64.md
@@ -7,7 +7,7 @@
## Description
-The TO_BASE64 function is used to convert an input string to Base64 encoded format. Base64 encoding can convert any binary data into a string composed of 64 characters.
+The TO_BASE64 function converts an input string to Base64 encoded format. Base64 is an encoding method based on 64 printable characters, commonly used to transmit data in protocols that don't support binary data, such as email, URL parameters, JSON, etc. This function follows the RFC 4648 standard, using the standard Base64 character set (A-Z, a-z, 0-9, +, /) and padding character (=).
## Syntax
@@ -16,7 +16,7 @@ TO_BASE64(<str>)
```
## Parameters
-| Parameter | Description |
+| Parameter | Description |
| --------- | ---------------------------------------------- |
| `<str>` | The string to be Base64 encoded. Type: VARCHAR |
@@ -24,32 +24,128 @@ TO_BASE64(<str>)
Returns VARCHAR type, representing the Base64 encoded string.
+Encoding rules:
+- Uses standard Base64 character set: A-Z, a-z, 0-9, +, /
+- Uses = as padding character, ensuring output length is a multiple of 4
+- Supports correct encoding of UTF-8 multi-byte characters
+- Output string contains only ASCII printable characters
+
Special cases:
- If input is NULL, returns NULL
-- If input is an empty string, returns an empty string
+- If input is empty string, returns empty string
+- Automatically handles UTF-8 character encoding
+- Output length is always 4/3 times the input byte count (rounded up to multiple of 4)
## Examples
-1. Single character encoding
+1. Basic character encoding
+```sql
+SELECT TO_BASE64('1'), TO_BASE64('A');
+```
+```text
++----------------+----------------+
+| TO_BASE64('1') | TO_BASE64('A') |
++----------------+----------------+
+| MQ== | QQ== |
++----------------+----------------+
+```
+
+2. Multi-character string encoding
+```sql
+SELECT TO_BASE64('234'), TO_BASE64('Hello');
+```
+```text
++------------------+--------------------+
+| TO_BASE64('234') | TO_BASE64('Hello') |
++------------------+--------------------+
+| MjM0 | SGVsbG8= |
++------------------+--------------------+
+```
+
+3. NULL and empty string handling
+```sql
+SELECT TO_BASE64(NULL), TO_BASE64('');
+```
+```text
++-----------------+---------------+
+| TO_BASE64(NULL) | TO_BASE64('') |
++-----------------+---------------+
+| NULL | |
++-----------------+---------------+
+```
+
+4. Long string encoding
```sql
-SELECT to_base64('1');
+SELECT TO_BASE64('Hello World'), TO_BASE64('The quick brown fox');
```
```text
-+----------------+
-| to_base64('1') |
-+----------------+
-| MQ== |
-+----------------+
++-------------------------+-------------------------------+
+| TO_BASE64('Hello World') | TO_BASE64('The quick brown fox') |
++-------------------------+-------------------------------+
+| SGVsbG8gV29ybGQ= | VGhlIHF1aWNrIGJyb3duIGZveA== |
++-------------------------+-------------------------------+
```
-2. Multiple character encoding
+5. Numbers and special characters
```sql
-SELECT to_base64('234');
+SELECT TO_BASE64('123456'), TO_BASE64('!@#$%^&*()');
```
```text
-+------------------+
-| to_base64('234') |
-+------------------+
-| MjM0 |
-+------------------+
-```
\ No newline at end of file
++---------------------+------------------------+
+| TO_BASE64('123456') | TO_BASE64('!@#$%^&*()') |
++---------------------+------------------------+
+| MTIzNDU2 | IUAjJCVeJiooKQ== |
++---------------------+------------------------+
+```
+
+6. UTF-8 multi-byte characters
+```sql
+SELECT TO_BASE64('ṭṛì'), TO_BASE64('ḍḍumai hello');
+```
+```text
++-------------------+---------------------------+
+| TO_BASE64('ṭṛì') | TO_BASE64('ḍḍumai hello') |
++-------------------+---------------------------+
+| 4bmt4bmb4bmA | 4bmN4bmNdW1haSBoZWxsbw== |
++-------------------+---------------------------+
+```
+
+7. Email address encoding
+```sql
+SELECT TO_BASE64('user@example.com'), TO_BASE64('admin.test@company.org');
+```
+```text
++------------------------------+-----------------------------------+
+| TO_BASE64('user@example.com') | TO_BASE64('admin.test@company.org') |
++------------------------------+-----------------------------------+
+| dXNlckBleGFtcGxlLmNvbQ== | YWRtaW4udGVzdEBjb21wYW55Lm9yZw== |
++------------------------------+-----------------------------------+
+```
+
+8. JSON data encoding
+```sql
+SELECT TO_BASE64('{"name":"John","age":30}'), TO_BASE64('[1,2,3,4,5]');
+```
+```text
++--------------------------------------+----------------------+
+| TO_BASE64('{"name":"John","age":30}') | TO_BASE64('[1,2,3,4,5]') |
++--------------------------------------+----------------------+
+| eyJuYW1lIjoiSm9obiIsImFnZSI6MzB9 | WzEsMiwzLDQsNV0= |
++--------------------------------------+----------------------+
+```
+
+9. Different length strings and padding
+```sql
+SELECT TO_BASE64('a'), TO_BASE64('ab'), TO_BASE64('abc');
+```
+```text
++----------------+-----------------+------------------+
+| TO_BASE64('a') | TO_BASE64('ab') | TO_BASE64('abc') |
++----------------+-----------------+------------------+
+| YQ== | YWI= | YWJj |
++----------------+-----------------+------------------+
+```
+
+### Keywords
+
+ TO_BASE64, BASE64
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/translate.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/translate.md
index 999a25127d7..f8e619f3617 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/translate.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/translate.md
@@ -7,7 +7,7 @@
## Description
-The TRANSLATE function is used for string replacement, converting characters in the source string according to mapping rules. It replaces characters in the source string that appear in the 'from' string with corresponding characters in the 'to' string.
+The TRANSLATE function performs character-by-character string replacement, converting characters in the source string according to mapping rules. This function replaces each character in the source string that appears in the 'from' string with the corresponding character at the same position in the 'to' string.
## Syntax
@@ -24,14 +24,20 @@ TRANSLATE(<source>, <from>, <to>)
## Return Value
-Returns VARCHAR type, representing the transformed string.
+Returns VARCHAR type, representing the string transformed according to character mapping rules.
+
+Character mapping rules:
+- Establishes one-to-one character mapping based on positions in 'from' and 'to' strings
+- 1st character in 'from' maps to 1st character in 'to', 2nd to 2nd, and so on
+- If 'from' contains duplicate characters, uses the first occurrence's mapping and ignores subsequent duplicates
+- Characters in source string not in 'from' string remain unchanged
Special cases:
- Returns NULL if any parameter is NULL
-- If there are duplicate characters in the 'from' string, only the first occurrence is used
-- If a source character is not in the 'from' string, it remains unchanged
-- If a character's position in the 'from' string exceeds the length of the 'to' string, the corresponding source character will be deleted
-- If both 'from' and 'to' are empty strings, returns the original string
+- Returns empty string if source is empty string
+- Returns original source string if 'from' is empty string
+- Deletes all characters from source that appear in 'from' if 'to' is empty string
+- If 'to' string is shorter than 'from', characters in source corresponding to excess 'from' characters are deleted
## Examples
@@ -83,14 +89,66 @@ SELECT translate('abcd', 'a', '');
+----------------------------+
```
-5. Duplicate characters in 'from' string
+5. Duplicate characters in 'from' string (uses first mapping only)
```sql
-SELECT translate('abcd', 'aac', 'zq');
+SELECT TRANSLATE('abacad', 'aac', 'zxy');
```
```text
-+--------------------------------+
-| translate('abcd', 'aac', 'zq') |
-+--------------------------------+
-| zbd |
-+--------------------------------+
-```
\ No newline at end of file
++-----------------------------------+
+| TRANSLATE('abacad', 'aac', 'zxy') |
++-----------------------------------+
+| zbzyzd |
++-----------------------------------+
+```
+
+6. 'to' string shorter than 'from' (deletes excess characters)
+```sql
+SELECT TRANSLATE('abcde', 'ace', 'xy');
+```
+```text
++-------------------------------+
+| TRANSLATE('abcde', 'ace', 'xy') |
++-------------------------------+
+| xbyd |
++-------------------------------+
+```
+
+7. UTF-8 character replacement
+```sql
+SELECT TRANSLATE('ṭṛì ḍḍumai', 'ṭṛ', 'ab');
+```
+```text
++-----------------------------------+
+| TRANSLATE('ṭṛì ḍḍumai', 'ṭṛ', 'ab') |
++-----------------------------------+
+| abì ḍḍumai |
++-----------------------------------+
+```
+
+8. Numeric character replacement
+```sql
+SELECT TRANSLATE('a1b2c3', '123', 'xyz');
+```
+```text
++----------------------------------+
+| TRANSLATE('a1b2c3', '123', 'xyz') |
++----------------------------------+
+| axbycz |
++----------------------------------+
+```
+
+9. Special symbol replacement
+```sql
+SELECT TRANSLATE('hello@world.com', '@.', '-_');
+```
+```text
++--------------------------------------------+
+| TRANSLATE('hello@world.com', '@.', '-_') |
++--------------------------------------------+
+| hello-world_com |
++--------------------------------------------+
+```
+
+### Keywords
+
+ TRANSLATE
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/trim-in.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/trim-in.md
index 98fca9d13c2..2412b9c8290 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/trim-in.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/trim-in.md
@@ -5,69 +5,121 @@
}
---
-## Description
+## Description
-When there is no `rhs` parameter, this function removes the leading and trailing spaces from the `str` string. When the `rhs` parameter is provided, it removes any characters from both ends of the string that are found in the `rhs` character set (order does not matter).
+The TRIM_IN function is used to remove leading and trailing specified characters from a string. If no character set is specified, it removes leading and trailing spaces by default. When a character set is specified, it removes all specified characters from both ends (regardless of their order in the set).
+The key feature of TRIM_IN is that it removes any combination of characters from the specified set, while the TRIM function removes characters based on exact string matching.
## Syntax
```sql
-TRIM_IN( <str> [ , <rhs>])
+TRIM_IN(<str>[, <rhs>])
```
-## Required Parameters
-
-| Parameters | Description |
-|------|------|
-| `<str>` | Delete spaces at both ends of the string |
+## Parameters
-## Optional Parameters
-
-| Parameters | Description |
-|------|------|
-| `<rhs>` | Remove the specified character |
+| Parameter | Description |
+| --------- | ------------------------------------------------------------------------ |
+| `<str>` | The string to be processed. Type: VARCHAR |
+| `<rhs>` | Optional parameter, the set of characters to be removed. Type: VARCHAR |
## Return Value
-Delete spaces at both ends or the string after the specified character
-
Returns VARCHAR type, representing the processed string.
Special cases:
- If str is NULL, returns NULL
- If rhs is not specified, removes all leading and trailing spaces
-- If rhs is specified, removes all characters from both ends that appear in rhs until encountering the first character not in rhs
+- If rhs is specified, removes all characters from both ends that appear in rhs until encountering characters not in rhs
## Examples
-1. Remove spaces from both ends:
+1. Remove leading and trailing spaces
```sql
-
SELECT trim_in(' ab d ') str;
```
+```text
++------+
+| str |
++------+
+| ab d |
++------+
+```
+2. Remove specified character set
```sql
-
+SELECT trim_in('ababccaab', 'ab') str;
+```
+```text
+------+
| str |
+------+
-| ab d|
+| cc |
+------+
```
+3. Comparison with TRIM function
+```sql
+SELECT trim_in('ababccaab', 'ab'), trim('ababccaab', 'ab');
+```
+```text
++-----------------------------+--------------------------+
+| trim_in('ababccaab', 'ab') | trim('ababccaab', 'ab') |
++-----------------------------+--------------------------+
+| cc | ababccaab |
++-----------------------------+--------------------------+
+```
+4. Character set order does not matter
```sql
-SELECT trim_in('ababccaab','ab') str;
+SELECT trim_in('abcHelloabc', 'cba');
+```
+```text
++--------------------------------+
+| trim_in('abcHelloabc', 'cba') |
++--------------------------------+
+| Hello |
++--------------------------------+
```
+5. UTF-8 character support
```sql
+SELECT trim_in('+++ṭṛì ḍḍumai+++', '+');
+```
+```text
++--------------------------------------+
+| trim_in('+++ṭṛì ḍḍumai+++', '+') |
++--------------------------------------+
+| ṭṛì ḍḍumai |
++--------------------------------------+
+```
-+------+
-| str |
-+------+
-| cc |
-+------+
+6. NULL value handling
+```sql
+SELECT trim_in(NULL, 'abc');
+```
+```text
++-----------------------+
+| trim_in(NULL, 'abc') |
++-----------------------+
+| NULL |
++-----------------------+
+```
+
+7. Empty character handling
+```sql
+SELECT trim_in('', 'abc'), trim_in('abc', '');
+```
+```text
++--------------------+--------------------+
+| trim_in('', 'abc') | trim_in('abc', '') |
++--------------------+--------------------+
+| | abc |
++--------------------+--------------------+
+```
+
+### Keywords
-```
\ No newline at end of file
+ TRIM_IN, TRIM
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/trim.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/trim.md
index 71de4507f60..d64f101437b 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/trim.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/trim.md
@@ -7,39 +7,37 @@
## Description
-This command is used to delete Spaces or specified characters at both ends of the string. If no rhs parameter is specified, delete the Spaces that appear continuously at the beginning of the right and left parts of str. Otherwise, delete rhs
+The TRIM function is used to remove consecutive spaces or specified strings from both ends of a string. If the second parameter is not specified, leading and trailing spaces are removed; if specified, the function removes the specified complete string from both ends.
## Syntax
```sql
-TRIM( <str> [ , <rhs>])
+TRIM(<str>[, <rhs>])
```
-## Required Parameters
+## Parameters
-| Parameters | Description |
-|------|------|
-| `<str>` | Deletes the Spaces at both ends of the string
-
-
-## Optional Parameters
-
-| Parameters | Description |
-|------|------|
-| `<rhs>` | removes the specified character |
+| Parameter | Description |
+| --------- | ----------- |
+| `<str>` | The string to be processed. Type: VARCHAR |
+| `<rhs>` | Optional parameter, characters to be trimmed from both ends. Type: VARCHAR |
## Return Value
-Deletes Spaces at both ends or the string after a specified character
+Returns a value of type VARCHAR.
+Special cases:
+- If any parameter is NULL, NULL is returned
+- If rhs is not specified, removes leading and trailing spaces
+- If rhs is specified, removes the complete rhs string from both ends (not character-by-character)
-## Example
+## Examples
+1. Remove leading and trailing spaces
```sql
SELECT trim(' ab d ') str;
```
-
-```sql
+```text
+------+
| str |
+------+
@@ -47,14 +45,90 @@ SELECT trim(' ab d ') str;
+------+
```
+2. Remove specified strings from both ends
```sql
-SELECT trim('ababccaab','ab') str;
+SELECT trim('ababccaab', 'ab') str;
+```
+```text
++---------+
+| str |
++---------+
+| ababcca |
++---------+
```
+3. UTF-8 character support
```sql
-+------+
-| str |
-+------+
-| cc |
-+------+
+SELECT trim(' ṭṛì ḍḍumai ');
+```
+```text
++------------------------------+
+| trim(' ṭṛì ḍḍumai ') |
++------------------------------+
+| ṭṛì ḍḍumai |
++------------------------------+
+```
+
+4. No matching prefix/suffix, return original string
+```sql
+SELECT trim('Hello World', 'xyz');
+```
+```text
++--------------------------------+
+| trim('Hello World', 'xyz') |
++--------------------------------+
+| Hello World |
++--------------------------------+
```
+
+5. NULL value handling
+```sql
+SELECT trim(NULL), trim('Hello', NULL);
+```
+```text
++------------+-----------------------+
+| trim(NULL) | trim('Hello', NULL) |
++------------+-----------------------+
+| NULL | NULL |
++------------+-----------------------+
+```
+
+6. Empty string handling
+```sql
+SELECT trim(''), trim('abc', '');
+```
+```text
++----------+------------------+
+| trim('') | trim('abc', '') |
++----------+------------------+
+| | abc |
++----------+------------------+
+```
+
+7. Repeated pattern removal from both ends
+```sql
+SELECT trim('abcabcabc', 'abc');
+```
+```text
++------------------------------+
+| trim('abcabcabc', 'abc') |
++------------------------------+
+| |
++------------------------------+
+```
+
+8. Asymmetric removal
+```sql
+SELECT trim('abcHelloabc', 'abc');
+```
+```text
++--------------------------------+
+| trim('abcHelloabc', 'abc') |
++--------------------------------+
+| Hello |
++--------------------------------+
+```
+
+### Keywords
+
+ TRIM
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/ucase.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/ucase.md
index b91148bc0c8..b8a384a1132 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/ucase.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/ucase.md
@@ -7,44 +7,133 @@
## Description
-Used to convert a string to uppercase letters
+The UCASE function (alias UPPER) converts all lowercase letters in a string to uppercase letters. This function supports Unicode character conversion and can correctly handle case conversion rules for various languages.
## Syntax
```sql
-UCASE( <str> )
-UPPER( <str> )
+UCASE(<str>)
+UPPER(<str>)
```
-## Required Parameters
-| Parameters | Description |
-|------|------|
-| `<str>` | The string to convert to uppercase
+## Parameters
+
+| Parameter | Description |
+|-----------|-------------|
+| `<str>` | The string to convert to uppercase. Type: VARCHAR |
## Return Value
-The value after converting the uppercase
+Returns VARCHAR type, representing the string converted to uppercase letters.
+
+Conversion rules:
+- Converts all lowercase letters in the string to corresponding uppercase letters
+- Non-letter characters (numbers, symbols, spaces, etc.) remain unchanged
+- Letters already in uppercase remain unchanged
-## Example
+Special cases:
+- Returns NULL if parameter is NULL
+- Returns empty string if string is empty
+- Returns original string if there are no lowercase letters
+## Examples
+
+1. Basic English letter conversion
```sql
-SELECT UCASE("aBc123"),UPPER("aBc123");
+SELECT UCASE('aBc123'), UPPER('aBc123');
```
-```sql
+```text
+-----------------+-----------------+
-| UCASE("aBc123") | UPPER("aBc123") |
+| UCASE('aBc123') | UPPER('aBc123') |
+-----------------+-----------------+
| ABC123 | ABC123 |
+-----------------+-----------------+
```
+2. Mixed character handling
```sql
-SELECT UCASE("Кириллица"),UPPER("Бәйтерек");
+SELECT UCASE('Hello World!'), UPPER('test@123');
```
+```text
++----------------------+------------------+
+| UCASE('Hello World!') | UPPER('test@123') |
++----------------------+------------------+
+| HELLO WORLD! | TEST@123 |
++----------------------+------------------+
+```
+
+3. NULL value handling
```sql
-+-----------------------------+---------------------------+
-| UCASE("Кириллица") | UPPER("Бәйтерек") |
-+-----------------------------+---------------------------+
-| КИРИЛЛИЦА | БӘЙТЕРЕК |
-+-----------------------------+---------------------------+
+SELECT UCASE(NULL), UPPER(NULL);
+```
+```text
++-------------+-------------+
+| UCASE(NULL) | UPPER(NULL) |
++-------------+-------------+
+| NULL | NULL |
++-------------+-------------+
+```
+
+4. Empty string handling
+```sql
+SELECT UCASE(''), UPPER('');
+```
+```text
++-----------+-----------+
+| UCASE('') | UPPER('') |
++-----------+-----------+
+| | |
++-----------+-----------+
+```
+
+5. Already uppercase string
+```sql
+SELECT UCASE('ALREADY UPPERCASE'), UPPER('ABC123');
+```
+```text
++---------------------------+----------------+
+| UCASE('ALREADY UPPERCASE') | UPPER('ABC123') |
++---------------------------+----------------+
+| ALREADY UPPERCASE | ABC123 |
++---------------------------+----------------+
```
+
+6. Numbers and symbols
+```sql
+SELECT UCASE('123!@#$%'), UPPER('price: $99.99');
+```
+```text
++-------------------+----------------------+
+| UCASE('123!@#$%') | UPPER('price: $99.99') |
++-------------------+----------------------+
+| 123!@#$% | PRICE: $99.99 |
++-------------------+----------------------+
+```
+
+7. UTF-8 multi-byte characters
+```sql
+SELECT UCASE('ṭṛì test'), UPPER('ḍḍumai hello');
+```
+```text
++--------------------+-----------------------+
+| UCASE('ṭṛì test') | UPPER('ḍḍumai hello') |
++--------------------+-----------------------+
+| ṬṚÌ TEST | ḌḌUMAI HELLO |
++--------------------+-----------------------+
+```
+
+8. Cyrillic letters
+```sql
+SELECT UCASE('Кириллица'), UPPER('Бәйтерек');
+```
+```text
++---------------------+-------------------+
+| UCASE('Кириллица') | UPPER('Бәйтерек') |
++---------------------+-------------------+
+| КИРИЛЛИЦА | БӘЙТЕРЕК |
++---------------------+-------------------+
+```
+
+### Keywords
+
+ UCASE, UPPER
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/uncompress.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/uncompress.md
index c49cf641e72..d9eec25ced5 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/uncompress.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/uncompress.md
@@ -6,7 +6,7 @@
---
## Description
-The UNCOMPRESS function is used to COMPRESS binary data into strings or values, you need to make sure that the binary data needs to be the result of 'compress'.
+The UNCOMPRESS function decompresses binary data into strings or values. You must ensure the binary data is the result of the `COMPRESS` function.
## Syntax
@@ -16,19 +16,19 @@ UNCOMPRESS(<compressed_str>)
## Parameters
-| Parameters | Description |
-|--------------------|---------------|
+| Parameter | Description |
+|--------------------|------------------------|
| `<compressed_str>` | Compressed binary data, parameter type is varchar or string |
-
## Return Value
-The return value is the same as the input `compressed_str` type
+The return value type is the same as the input `compressed_str` type.
Special cases:
-- `compressed_str` Returns NULL if the binary data is not compressed.
+- Returns NULL if `compressed_str` is not binary data obtained from `COMPRESS`.
+
-## Example
+## Examples
``` sql
select uncompress(compress('abc'));
@@ -51,7 +51,7 @@ select uncompress(compress(''));
+--------------------------+
```
```sql
-select uncompress(compress(abc));
+select uncompress('abc');
```
```text
+-------------------+
@@ -59,4 +59,8 @@ select uncompress(compress(abc));
+-------------------+
| NULL |
+-------------------+
-```
\ No newline at end of file
+```
+
+### Keywords
+
+ UNCOMPRESS, COMPRESS
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/unhex.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/unhex.md
index d5f5978d501..8c9fa0cee8d 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/unhex.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/unhex.md
@@ -7,11 +7,10 @@
## Description
-The `unhex` function is used to convert a hexadecimal string back into the original string. It converts every two hexadecimal characters into one byte. When an invalid value is passed as a parameter, it will return empty string.
-The `unhex_null` function has the same effect as the `unhex` function. However, when an invalid value is passed as a parameter, it will return NULL.
+The UNHEX function converts a hexadecimal string back to the original string, serving as the inverse operation of the HEX function. This function converts every two hexadecimal characters (0-9, A-F, a-f) into one byte. The UNHEX_NULL function works identically but returns NULL instead of an empty string when encountering invalid input. These functions are useful when handling binary data, encrypted data, or data requiring hexadecimal representation.
:::tip
-`unhex_null` function is supported since version 3.0.6.
+This function is supported since version 3.0.6.
:::
## Syntax
@@ -28,9 +27,22 @@ UNHEX(<str>)
## Return Value
-If the input string has a length of 0 or is odd, `unhex` function returns an empty string while `unhex_null` function returns `NULL`.
-If the string contains characters other than [0-9], [a-f], or [A-F], `unhex` function returns an empty string while `unhex_null` function returns `NULL`.
-In other cases, every two characters are converted to their hexadecimal representation and concatenated into a string for output.
+Returns VARCHAR type, representing the decoded original string from hexadecimal.
+
+Decoding rules:
+- Accepts character range: 0-9, a-f, A-F
+- Every two hexadecimal characters convert to one byte
+- Result may contain unprintable characters
+
+Special cases (UNHEX):
+- If input is NULL, returns empty string
+- If string length is 0 or odd, returns empty string
+- If contains non-hexadecimal characters, returns empty string
+
+Special cases (UNHEX_NULL):
+- If input is NULL, returns NULL
+- If string length is 0 or odd, returns NULL
+- If contains non-hexadecimal characters, returns NULL
## Examples
@@ -71,13 +83,53 @@ select unhex('41');
```
```sql
-select unhex('4142');
+select unhex('4142'), unhex('48656C6C6F');
+```
+
+```text
++---------------+----------------------+
+| unhex('4142') | unhex('48656C6C6F') |
++---------------+----------------------+
+| AB | Hello |
++---------------+----------------------+
+```
+
+5. NULL handling comparison
+```sql
+SELECT UNHEX(NULL), UNHEX_NULL(NULL);
+```
+```text
++-------------+-----------------+
+| UNHEX(NULL) | UNHEX_NULL(NULL) |
++-------------+-----------------+
+| | NULL |
++-------------+-----------------+
+```
+
+6. UTF-8 character decoding
+```sql
+SELECT UNHEX('E4B8AD'), UNHEX('E69687');
+```
+```text
++-----------------+-----------------+
+| UNHEX('E4B8AD') | UNHEX('E69687') |
++-----------------+-----------------+
+| 中 | 文 |
++-----------------+-----------------+
```
+7. Hexadecimal encoding-decoding cycle verification
+```sql
+SELECT UNHEX(HEX('Hello')), UNHEX(HEX('Test123'));
+```
```text
-+---------------+
-| unhex('4142') |
-+---------------+
-| AB |
-+---------------+
++---------------------+------------------------+
+| UNHEX(HEX('Hello')) | UNHEX(HEX('Test123')) |
++---------------------+------------------------+
+| Hello | Test123 |
++---------------------+------------------------+
```
+
+### Keywords
+
+ UNHEX, UNHEX_NULL, HEX
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/uuid-to-int.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/uuid-to-int.md
new file mode 100644
index 00000000000..7b108bbc0b7
--- /dev/null
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/uuid-to-int.md
@@ -0,0 +1,113 @@
+---
+{
+ "title": "UUID_TO_INT",
+ "language": "en"
+}
+---
+
+## Description
+
+The UUID_TO_INT function converts a UUID string to its INT128 integer representation. This is useful for scenarios where UUIDs need to be stored as integers in the database.
+
+## Syntax
+
+```sql
+UUID_TO_INT(<uuid>)
+```
+
+## Parameters
+
+| Parameter | Description |
+| -------- | ----------------------------------------- |
+| `<uuid>` | UUID string to convert. Type: VARCHAR |
+
+## Return Value
+
+Returns INT128 type, the integer representation of the UUID.
+
+Special cases:
+- If parameter is NULL, returns NULL
+- If UUID format is invalid, returns NULL
+
+## Examples
+
+1. Basic usage: UUID to integer
+```sql
+SELECT uuid_to_int('6ce4766f-6783-4b30-b357-bba1c7600348');
+```
+```text
++-----------------------------------------------------+
+| uuid_to_int('6ce4766f-6783-4b30-b357-bba1c7600348') |
++-----------------------------------------------------+
+| 95721955514869408091759290071393952876 |
++-----------------------------------------------------+
+```
+
+2. NULL value handling
+```sql
+SELECT uuid_to_int(NULL);
+```
+```text
++-------------------+
+| uuid_to_int(NULL) |
++-------------------+
+| NULL |
++-------------------+
+```
+
+3. Using with UUID()
+```sql
+SELECT uuid_to_int(UUID());
+```
+```text
++----------------------------------------+
+| uuid_to_int(UUID()) |
++----------------------------------------+
+| 65543688548341017423158579845706592446 |
++----------------------------------------+
+```
+
+4. Batch conversion
+```sql
+SELECT uuid, uuid_to_int(uuid) AS uuid_int
+FROM (SELECT '6ce4766f-6783-4b30-b357-bba1c7600348' AS uuid) t;
+```
+```text
++--------------------------------------+--------------------------------------+
+| uuid | uuid_int |
++--------------------------------------+--------------------------------------+
+| 6ce4766f-6783-4b30-b357-bba1c7600348 | 95721955514869408091759290071393952876|
++--------------------------------------+--------------------------------------+
+```
+
+5. Uppercase UUID conversion
+
+```sql
+SELECT uuid_to_int('6CE4766F-6783-4B30-B357-BBA1C7600348');
+```
+
+```text
++-----------------------------------------------------+
+| uuid_to_int('6CE4766F-6783-4B30-B357-BBA1C7600348') |
++-----------------------------------------------------+
+| 95721955514869408091759290071393952876 |
++-----------------------------------------------------+
+```
+
+6. Invalid UUID format
+
+```sql
+SELECT uuid_to_int('invalid-uuid-format');
+```
+
+```text
++------------------------------------+
+| uuid_to_int('invalid-uuid-format') |
++------------------------------------+
+| NULL |
++------------------------------------+
+```
+
+### Keywords
+
+ UUID_TO_INT
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/uuid.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/uuid.md
index 44f635573ae..581f855a2ff 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/uuid.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/uuid.md
@@ -7,27 +7,53 @@
## Description
-Used to return a randomly generated UUID string.
+The UUID function generates a random Universally Unique Identifier (UUID). The generated UUID conforms to RFC 4122 standard, with a format of 8-4-4-4-12 (36 characters including hyphens).
## Syntax
```sql
UUID()
```
+
+## Parameters
+
+No parameters.
+
## Return Value
-Returns a randomly generated UUID string.
+
+Returns VARCHAR type, a randomly generated UUID string.
+
+Special cases:
+- Each call generates a different UUID
+- UUID format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
+- Generated UUID is globally unique
## Examples
+1. Basic usage: generate single UUID
```sql
-select UUID();
+SELECT UUID();
```
-
-```sql
+```text
+--------------------------------------+
| UUID() |
+--------------------------------------+
| 29077778-fc5e-4603-8368-6b5f8fd55c24 |
+--------------------------------------+
+```
+
+2. Multiple calls generate different UUIDs
+```sql
+SELECT UUID(), UUID();
+```
+```text
++--------------------------------------+--------------------------------------+
+| UUID() | UUID() |
++--------------------------------------+--------------------------------------+
+| a1b2c3d4-e5f6-47a8-b9c0-d1e2f3a4b5c6 | f7e8d9c0-b1a2-4938-8756-c4d3e2f1a0b9 |
++--------------------------------------+--------------------------------------+
+```
+
+### Keywords
-```
\ No newline at end of file
+ UUID
\ No newline at end of file
diff --git a/docs/sql-manual/sql-functions/scalar-functions/string-functions/xpath-string.md b/docs/sql-manual/sql-functions/scalar-functions/string-functions/xpath-string.md
index 3592ceca6be..c278fe71832 100644
--- a/docs/sql-manual/sql-functions/scalar-functions/string-functions/xpath-string.md
+++ b/docs/sql-manual/sql-functions/scalar-functions/string-functions/xpath-string.md
@@ -84,12 +84,16 @@ SELECT xpath_string('<a><b>1</b><b>2</b></a>', '/a/b[2]');
5. Handling CDATA and comments
```sql
-SELECT xpath_string('<a><![CDATA[123]]></a>', '/a'), xpath_string('<a><!-- comment -->123</a>', '/a');
+SELECT xpath_string(NULL, '/a');
```
```text
-+-----------------------------------------------+---------------------------------------------------+
-| xpath_string('<a><![CDATA[123]]></a>', '/a') | xpath_string('<a><!-- comment -->123</a>', '/a') |
-+-----------------------------------------------+---------------------------------------------------+
-| 123 | 123 |
-+-----------------------------------------------+---------------------------------------------------+
++--------------------------+
+| xpath_string(NULL, '/a') |
++--------------------------+
+| NULL |
++--------------------------+
```
+
+### Keywords
+
+ XPATH_STRING, XPATH, XML
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/append-trailing-char-if-absent.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/append-trailing-char-if-absent.md
index 8f4135f9e37..d287fa37b93 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/append-trailing-char-if-absent.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/append-trailing-char-if-absent.md
@@ -7,35 +7,89 @@
## 描述
-用于在字符串末尾添加特定字符(如空格、特定符号等),如果该字符不存在于字符串的结尾时进行添加。函数的作用是确保字符串以特定字符结尾。
+APPEND_TRAILING_CHAR_IF_ABSENT 函数用于确保字符串以指定字符结尾。如果字符串末尾不存在该字符,则添加;如果已存在,则保持不变。
## 语法
```sql
-APPEND_TRAILING_CHAR_IF_ABSENT ( <str> , <trailing_char> )
+APPEND_TRAILING_CHAR_IF_ABSENT(<str>, <trailing_char>)
```
## 参数
-| 参数 | 说明 |
-|-------------------|-----------------------------|
-| `<str>` | 需要判断的目标字符串 |
-| `<trailing_char>` | 需要添加到字符串末尾的字符(如果该字符不存在的话) |
+| 参数 | 说明 |
+| ------------------ | ----------------------------------------- |
+| `<str>` | 需要处理的目标字符串。类型:VARCHAR |
+| `<trailing_char>` | 需要确保出现在字符串末尾的字符。类型:VARCHAR |
## 返回值
-参数 `<str>` 与 `<trailing_char>` 拼接后的字符串(如果 `<trailing_char>` 不存在于 `<str>` )
+返回 VARCHAR 类型:
+- 如果 `<str>` 末尾不存在 `<trailing_char>`,返回 `<str>` 与 `<trailing_char>` 拼接后的字符串
+- 如果 `<str>` 末尾已存在 `<trailing_char>`,返回原始 `<str>`
-## 举例
+特殊情况:
+- 如果任意参数为 NULL,返回 NULL
+- 如果 `<str>` 为空字符串,返回 `<trailing_char>`
-``` sql
-SELECT APPEND_TRAILING_CHAR_IF_ABSENT('a','c'),APPEND_TRAILING_CHAR_IF_ABSENT('ac', 'c'),APPEND_TRAILING_CHAR_IF_ABSENT('ac', 'cd')
+## 示例
+
+1. 基本用法:字符不存在时添加
+```sql
+SELECT APPEND_TRAILING_CHAR_IF_ABSENT('a', 'c');
+```
+```text
++------------------------------------------+
+| append_trailing_char_if_absent('a', 'c') |
++------------------------------------------+
+| ac |
++------------------------------------------+
+```
+
+2. 字符已存在时不添加
+```sql
+SELECT APPEND_TRAILING_CHAR_IF_ABSENT('ac', 'c');
+```
+```text
++-------------------------------------------+
+| append_trailing_char_if_absent('ac', 'c') |
++-------------------------------------------+
+| ac |
++-------------------------------------------+
+```
+
+3. 空字符串处理
+```sql
+SELECT APPEND_TRAILING_CHAR_IF_ABSENT('', '/');
+```
+```text
++------------------------------------------+
+| append_trailing_char_if_absent('', '/') |
++------------------------------------------+
+| / |
++------------------------------------------+
+```
+
+4. NULL 值处理
+```sql
+SELECT APPEND_TRAILING_CHAR_IF_ABSENT(NULL, 'c');
+```
+```text
++-------------------------------------------+
+| append_trailing_char_if_absent(NULL, 'c') |
++-------------------------------------------+
+| NULL |
++-------------------------------------------+
```
-```text
-+------------------------------------------+-------------------------------------------+--------------------------------------------+
-| append_trailing_char_if_absent('a', 'c') | append_trailing_char_if_absent('ac', 'c') | append_trailing_char_if_absent('ac', 'cd') |
-+------------------------------------------+-------------------------------------------+--------------------------------------------+
-| ac | ac | accd |
-+------------------------------------------+-------------------------------------------+--------------------------------------------+
+5. utf-8 字符
+```sql
+SELECT APPEND_TRAILING_CHAR_IF_ABSENT('acf', 'ṛ');
```
+```text
++----------------------------------------------+
+| APPEND_TRAILING_CHAR_IF_ABSENT('acf', 'ṛ') |
++----------------------------------------------+
+| acfṛ |
++----------------------------------------------+
+```
\ No newline at end of file
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/ascii.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/ascii.md
index ef5ad09ad64..c0925e54359 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/ascii.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/ascii.md
@@ -7,34 +7,136 @@
## 描述
-返回字符串第一个字符对应的 ascii 码
+返回字符串第一个字符对应的 ASCII 码值。该函数仅处理字符串的第一个字符,对于多字符字符串只返回首字符的 ASCII 值。
## 语法
```sql
-ASCII ( <str> )
+ASCII(<str>)
```
## 参数
| 参数 | 说明 |
|---------|-----------------------------|
-| `<str>` | 需要被计算第一个字符的 ascii 码的字符串 |
+| `<str>` | 需要获取第一个字符 ASCII 码的字符串。类型:VARCHAR |
## 返回值
-参数 <str> 第一个字符的 ascii 码
+返回 INT 类型,表示字符串第一个字符的 ASCII 码值。
-## 举例
+特殊情况:
+- 如果参数为 NULL,返回 NULL
+- 如果字符串为空,返回 0
+- 如果第一个字符不是 ASCII 字符(码值大于 127),返回对应的字节值
+- 对于多字节 UTF-8 字符,返回第一个字节的值
+## 示例
+
+1. 基本数字字符
```sql
-SELECT ASCII('1'),ASCII('234')
+SELECT ASCII('1'), ASCII('234');
```
-
```text
+------------+--------------+
-| ascii('1') | ascii('234') |
+| ASCII('1') | ASCII('234') |
+------------+--------------+
| 49 | 50 |
+------------+--------------+
-```
\ No newline at end of file
+```
+
+2. 字母字符
+```sql
+SELECT ASCII('A'), ASCII('a'), ASCII('Z');
+```
+```text
++------------+------------+------------+
+| ASCII('A') | ASCII('a') | ASCII('Z') |
++------------+------------+------------+
+| 65 | 97 | 90 |
++------------+------------+------------+
+```
+
+3. 空字符串处理
+```sql
+SELECT ASCII('');
+```
+```text
++----------+
+| ASCII('') |
++----------+
+| 0 |
++----------+
+```
+
+4. NULL 值处理
+```sql
+SELECT ASCII(NULL);
+```
+```text
++-------------+
+| ASCII(NULL) |
++-------------+
+| NULL |
++-------------+
+```
+
+5. 特殊符号
+```sql
+SELECT ASCII(' '), ASCII('!'), ASCII('@');
+```
+```text
++------------+------------+------------+
+| ASCII(' ') | ASCII('!') | ASCII('@') |
++------------+------------+------------+
+| 32 | 33 | 64 |
++------------+------------+------------+
+```
+
+6. 控制字符
+```sql
+SELECT ASCII('\t'), ASCII('\n'), ASCII('\r');
+```
+```text
++-------------+-------------+-------------+
+| ASCII('\t') | ASCII('\n') | ASCII('\r') |
++-------------+-------------+-------------+
+| 9 | 10 | 13 |
++-------------+-------------+-------------+
+```
+
+7. 多字符字符串(只返回第一个字符)
+```sql
+SELECT ASCII('Hello'), ASCII('World123');
+```
+```text
++----------------+------------------+
+| ASCII('Hello') | ASCII('World123') |
++----------------+------------------+
+| 72 | 87 |
++----------------+------------------+
+```
+
+8. UTF-8 多字节字符
+```sql
+SELECT ASCII('ṭṛì'), ASCII('ḍḍumai');
+```
+```text
++---------------+------------------+
+| ASCII('ṭṛì') | ASCII('ḍḍumai') |
++---------------+------------------+
+| 225 | 225 |
++---------------+------------------+
+```
+
+9. 数字与字符混合
+```sql
+SELECT ASCII('9abc'), ASCII('0xyz');
+```
+```text
++---------------+---------------+
+| ASCII('9abc') | ASCII('0xyz') |
++---------------+---------------+
+| 57 | 48 |
++---------------+---------------+
+```
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/auto-partition-name.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/auto-partition-name.md
index 058333e1bbf..ff31f0deb1f 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/auto-partition-name.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/auto-partition-name.md
@@ -1,100 +1,110 @@
---
{
"title": "AUTO_PARTITION_NAME",
- "language": "en"
+ "language": "zh-CN"
}
---
-:::tip tip
-Supported since Apache Doris 2.1.6
-:::
+## 描述
-### Description
-#### Syntax
+AUTO_PARTITION_NAME 函数用于生成自动分区的分区名称。支持两种模式:RANGE 模式按时间单位生成分区名,LIST 模式根据字符串生成分区名。
-`VARCHAR AUTO_PARTITION_NAME('RANGE', 'VARCHAR unit', DATETIME datetime)`
+自 Apache Doris 2.1.6 版本开始支持。
-`VARCHAR AUTO_PARTITION_NAME('LIST', VARCHAR,...)`
+## 语法
-Generate datetime partition names by unit following RANGE's partition name rules
+```sql
+AUTO_PARTITION_NAME('RANGE', <unit>, <datetime>)
+AUTO_PARTITION_NAME('LIST', <value>[, <value> ...])
+```
+
+## 参数
-Convert strings to partition names following LIST's partition name rules
+| 参数 | 说明 |
+| ----------- | ----------------------------------------- |
+| `'RANGE'` | RANGE 分区模式,根据时间生成分区名 |
+| `'LIST'` | LIST 分区模式,根据字符串值生成分区名 |
+| `<unit>` | RANGE 模式的时间单位:`year`、`month`、`day`、`hour`、`minute`、`second`。类型:VARCHAR |
+| `<datetime>` | RANGE 模式的日期时间值。类型:DATETIME |
+| `<value>` | LIST 模式的分区值(可多个)。类型:VARCHAR |
-The datetime parameter is a legal date expression.
+## 返回值
-The unit parameter is the time interval you want, the available values are: [`second`, `minute`, `hour`, `day`, `month`, `year`].
-If unit does not match one of these options, a syntax error will be returned.
+返回 VARCHAR 类型,为生成的分区名称。
-**Supported since Doris 2.1.6**
+特殊情况:
+- RANGE 模式:分区名格式为 `pYYYYMMDDHHMMSS`,根据 unit 截断到对应精度
+- LIST 模式:分区名格式为 `p<value><length>`,多个值用长度分隔
+- 如果参数无效,返回错误
-### Example
+## 示例
+1. 基本用法:RANGE 按天分区
```sql
-mysql> select auto_partition_name('range', 'years', '123');
-ERROR 1105 (HY000): errCode = 2, detailMessage = range auto_partition_name must accept year|month|day|hour|minute|second for 2nd argument
+SELECT auto_partition_name('range', 'day', '2022-12-12 19:20:30');
+```
+```text
++------------------------------------------------------------+
+| auto_partition_name('range', 'day', '2022-12-12 19:20:30') |
++------------------------------------------------------------+
+| p20221212000000 |
++------------------------------------------------------------+
+```
-mysql> select auto_partition_name('range', 'year', '2022-12-12 19:20:30');
-+---------------------------------------------------------------+
-| auto_partition_name('range', 'year', '2022-12-12 19:20:30') |
-+---------------------------------------------------------------+
-| p20220101000000 |
-+---------------------------------------------------------------+
-
-mysql> select auto_partition_name('range', 'month', '2022-12-12 19:20:30');
-+---------------------------------------------------------------+
-| auto_partition_name('range', 'month', '2022-12-12 19:20:30') |
-+---------------------------------------------------------------+
-| p20221201000000 |
-+---------------------------------------------------------------+
-
-mysql> select auto_partition_name('range', 'day', '2022-12-12 19:20:30');
-+---------------------------------------------------------------+
-| auto_partition_name('range', 'day', '2022-12-12 19:20:30') |
-+---------------------------------------------------------------+
-| p20221212000000 |
-+---------------------------------------------------------------+
-
-mysql> select auto_partition_name('range', 'hour', '2022-12-12 19:20:30');
-+---------------------------------------------------------------+
-| auto_partition_name('range', 'hour', '2022-12-12 19:20:30') |
-+---------------------------------------------------------------+
-| p20221212190000 |
-+---------------------------------------------------------------+
-
-mysql> select auto_partition_name('range', 'minute', '2022-12-12 19:20:30');
-+---------------------------------------------------------------+
-| auto_partition_name('range', 'minute', '2022-12-12 19:20:30') |
-+---------------------------------------------------------------+
-| p20221212192000 |
-+---------------------------------------------------------------+
-
-mysql> select auto_partition_name('range', 'second', '2022-12-12 19:20:30');
-+---------------------------------------------------------------+
-| auto_partition_name('range', 'second', '2022-12-12 19:20:30') |
-+---------------------------------------------------------------+
-| p20221212192030 |
-+---------------------------------------------------------------+
-
-mysql> select auto_partition_name('list', 'helloworld');
+2. RANGE 按月分区
+```sql
+SELECT auto_partition_name('range', 'month', '2022-12-12 19:20:30');
+```
+```text
++--------------------------------------------------------------+
+| auto_partition_name('range', 'month', '2022-12-12 19:20:30') |
++--------------------------------------------------------------+
+| p20221201000000 |
++--------------------------------------------------------------+
+```
+
+3. LIST 单个值
+```sql
+SELECT auto_partition_name('list', 'helloworld');
+```
+```text
+-------------------------------------------+
| auto_partition_name('list', 'helloworld') |
+-------------------------------------------+
| phelloworld10 |
+-------------------------------------------+
+```
-mysql> select auto_partition_name('list', 'hello', 'world');
+4. LIST 多个值
+```sql
+SELECT auto_partition_name('list', 'hello', 'world');
+```
+```text
+-----------------------------------------------+
| auto_partition_name('list', 'hello', 'world') |
+-----------------------------------------------+
| phello5world5 |
+-----------------------------------------------+
+```
-mysql> select auto_partition_name('list', "你好");
-+------------------------------------+
-| auto_partition_name('list', "你好") |
-+------------------------------------+
-| p4f60597d2 |
-+------------------------------------+
+5. UTF-8 特殊字符支持:LIST 模式
+```sql
+SELECT auto_partition_name('list', 'ṭṛì', 'ḍḍumai');
+```
+```text
++------------------------------------------------+
+| auto_partition_name('list', 'ṭṛì', 'ḍḍumai') |
++------------------------------------------------+
+| pṭṛì9ḍḍumai12 |
++------------------------------------------------+
+```
+
+6. 无效的 unit 参数
+```sql
+SELECT auto_partition_name('range', 'years', '2022-12-12');
+```
+```text
+ERROR 1105 (HY000): errCode = 2, detailMessage = range auto_partition_name must accept year|month|day|hour|minute|second for 2nd argument
```
### Keywords
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/char-length.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/char-length.md
index 22b9140a1ad..8cbf5fb3539 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/char-length.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/char-length.md
@@ -7,9 +7,9 @@
## 描述
-计算字符串的长度,对于多字节字符,返回字符数。
+CHAR_LENGTH 函数用于计算字符串的字符数(而非字节数)。对于多字节字符(如中文),返回的是字符个数。
-目前仅支持 `utf8` 编码
+目前仅支持 UTF-8 编码。
## 别名
@@ -18,29 +18,70 @@
## 语法
```sql
-CHAR_LENGTH ( <str> )
+CHAR_LENGTH(<str>)
```
## 参数
-| 参数 | 说明 |
-|---------|------------|
-| `<str>` | 需要计算长度的字符串 |
+| 参数 | 说明 |
+| ------- | ----------------------------------------- |
+| `<str>` | 需要计算字符长度的字符串。类型:VARCHAR |
## 返回值
-字符串 <str> 的长度。
+返回 INT 类型,表示字符串的字符数。
-## 举例
+特殊情况:
+- 如果参数为 NULL,返回 NULL
+- 空字符串返回 0
+- 多字节 UTF-8 字符每个字符计数为 1
+## 示例
+
+1. 英文字符
+```sql
+SELECT CHAR_LENGTH('hello');
+```
+```text
++----------------------+
+| char_length('hello') |
++----------------------+
+| 5 |
++----------------------+
+```
+
+2. 中文字符(每个汉字算一个字符)
```sql
-select CHAR_LENGTH("abc"),CHAR_LENGTH("中国")
+SELECT CHAR_LENGTH('中国');
+```
+```text
++----------------------+
+| char_length('中国') |
++----------------------+
+| 2 |
++----------------------+
```
+3. NULL 值处理
+```sql
+SELECT CHAR_LENGTH(NULL);
+```
+```text
++--------------------+
+| char_length(NULL) |
++--------------------+
+| NULL |
++--------------------+
+```
+
+4. 与 LENGTH 函数对比(LENGTH 返回字节数)
+```sql
+SELECT CHAR_LENGTH('中国') AS char_len, LENGTH('中国') AS byte_len;
+```
```text
-+-------------------------+----------------------------+
-| character_length('abc') | character_length('中国') |
-+-------------------------+----------------------------+
-| 3 | 2 |
-+-------------------------+----------------------------+
++----------+----------+
+| char_len | byte_len |
++----------+----------+
+| 2 | 6 |
++----------+----------+
```
\ No newline at end of file
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/char.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/char.md
index 8f15bdd798c..b3e26171144 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/char.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/char.md
@@ -7,44 +7,75 @@
## 描述
-将每个参数解释为整数,并返回一个字符串,该字符串由这些整数的代码值给出的字符组成。特殊情况:
-
-- 如果结果字符串对于给定字符集是非法的,相应的转换结果为 NULL 值。
-
-- 大于 `255` 的参数将转换为多个结果字节。例如,`char(15049882)`等价于`char(229, 164, 154)`。
-
+CHAR 函数将每个参数解释为整数,并返回一个由这些整数代码值组成字符的字符串。
## 语法
```sql
-CHAR ( <expr> [ , <expr> ... ] [ USING <charset_name> ] )
+CHAR(<expr>[, <expr> ...] [USING <charset_name>])
```
## 参数
-| 参数 | 说明 |
-|------------------|---------------------|
-| `<expr>` | 需要被计算为字符的整数 |
-| `<charset_name>` | 返回值的编码,目前只支持 `utf8` |
+| 参数 | 说明 |
+| ------------------ | ----------------------------------------- |
+| `<expr>` | 需要转换为字符的整数代码值。类型:INT |
## 返回值
-参数列表 `<expr>` 对应字符组成的字符串。特殊情况:
+返回 VARCHAR 类型,为由参数整数代码值对应字符组成的字符串。
+
+特殊情况:
+- 如果任意参数为 NULL,返回空字符串
+- 如果结果字符串对于给定字符集是非法的,返回 NULL
+- 大于 255 的参数会被转换为多字节字符。例如 `CHAR(15049882)` 等价于 `CHAR(229, 164, 154)`
-- 如果结果字符串对于给定字符集是非法的,相应的转换结果为 NULL 值。
+## 示例
-- 大于 `255` 的参数将转换为多个结果字节。例如,`CHAR(15049882)`等价于`CHAR(229, 164, 154)`。
+1. 基本用法:ASCII 字符生成
+```sql
+SELECT CHAR(68, 111, 114, 105, 115);
+```
+```text
++--------------------------------------+
+| char('utf8', 68, 111, 114, 105, 115) |
++--------------------------------------+
+| Doris |
++--------------------------------------+
+```
-## 举例
+2. 多字节 UTF-8 字符(中文)
+```sql
+SELECT CHAR(15049882, 15179199, 14989469);
+```
+```text
++--------------------------------------------+
+| char('utf8', 15049882, 15179199, 14989469) |
++--------------------------------------------+
+| 多睿丝 |
++--------------------------------------------+
+```
+3. 非法字符返回 NULL
```sql
-SELECT CHAR(68, 111, 114, 105, 115),CHAR(15049882, 15179199, 14989469),CHAR(255)
+SELECT CHAR(255);
+```
+```text
++-------------------+
+| char('utf8', 255) |
++-------------------+
+| NULL |
++-------------------+
```
+4. NULL 值处理
+```sql
+SELECT CHAR(NULL);
+```
```text
-+--------------------------------------+--------------------------------------------+-------------------+
-| char('utf8', 68, 111, 114, 105, 115) | char('utf8', 15049882, 15179199, 14989469) | char('utf8', 255) |
-+--------------------------------------+--------------------------------------------+-------------------+
-| Doris | 多睿丝 | NULL |
-+--------------------------------------+--------------------------------------------+-------------------+
++------------+
+| CHAR(NULL) |
++------------+
+| |
++------------+
```
\ No newline at end of file
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/compress.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/compress.md
index b8093140ca3..2a52130763a 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/compress.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/compress.md
@@ -6,44 +6,46 @@
---
## 描述
-COMPRESS 函数用于将字符串或值压缩成二进制数据,压缩后的数据可通过 `UNCOMPRESS` 函数解压还原。
+
+COMPRESS 函数用于将字符串压缩成二进制数据。使用 zlib 压缩算法,压缩后的数据可通过 UNCOMPRESS 函数解压还原。
## 语法
```sql
-COMPRESS(<uncompressed_str>)
+COMPRESS(<str>)
```
## 参数
-| 参数 | 说明 |
-|--------------------|---------------|
-| `<uncompressed_str>` | 未压缩的原串,参数类型是 varchar 或者 string |
+| 参数 | 说明 |
+| -------- | ----------------------------------------- |
+| `<str>` | 需要压缩的字符串。类型:VARCHAR |
## 返回值
-返回串与输入的 `uncompressed_str` 类型一致
-
-返回串是不可读的压缩字节流。
+返回 VARCHAR 类型,为压缩后的二进制数据(不可读)。
特殊情况:
-- `uncompressed_str` 输入为 empty string(`''`) 时,返回 empty string(`''`)
+- 如果参数为 NULL,返回 NULL
+- 如果输入为空字符串 `''`,返回空字符串 `''`
-## 举例
+## 示例
-``` sql
-select uncompress(compress('abc'));
+1. 基本用法:压缩和解压
+```sql
+SELECT uncompress(compress('hello'));
```
```text
-+-----------------------------+
-| uncompress(compress('abc')) |
-+-----------------------------+
-| abc |
-+-----------------------------+
++-------------------------------+
+| uncompress(compress('hello')) |
++-------------------------------+
+| hello |
++-------------------------------+
```
+2. 空字符串处理
```sql
-select compress('');
+SELECT compress('');
```
```text
+--------------+
@@ -51,4 +53,28 @@ select compress('');
+--------------+
| |
+--------------+
+```
+
+3. NULL 值处理
+```sql
+SELECT compress(NULL);
+```
+```text
++----------------+
+| compress(NULL) |
++----------------+
+| NULL |
++----------------+
+```
+
+4. utf-8 字符测试
+```sql
+SELECT uncompress(compress('ṭṛì'));
+```
+```text
++----------------------------------+
+| uncompress(compress('ṭṛì')) |
++----------------------------------+
+| ṭṛì |
++----------------------------------+
```
\ No newline at end of file
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/concat-ws.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/concat-ws.md
index a90445b8f6a..64a1ad9a55b 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/concat-ws.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/concat-ws.md
@@ -7,163 +7,160 @@
## 描述
-使用第一个参数sep作为连接符,将第二个参数及后续所有参数(或一个数组、多个数组中的所有字符串)拼接成一个字符串。特殊情况:
+CONCAT_WS 函数(Concatenate With Separator)用于使用指定的分隔符连接多个字符串或数组。与 CONCAT 函数不同,CONCAT_WS 会自动跳过 NULL 值(但不跳过空字符串),并在非 NULL 值之间插入分隔符。该函数支持字符串参数和数组参数两种模式,在生成 CSV 格式、路径拼接、标签列表等场景中非常有用。
-- 若分隔符为 NULL,则返回 NULL。
-- CONCAT_WS函数不跳过空字符串(""),但会跳过 NULL 值。
-- CONCAT_WS函数不跳过任何数组参数中的空字符串,但会跳过数组中的NULL 值。
-- CONCAT_WS函数不会跳过NULL如果输入多个数组参数,会返回空字符串。
-- 第一个参数必须为字符串类型(string 或 varchar),其他参数必须为相同类型,即均为字符串类型(string 或 varchar)或均为数组类型(ARRAY)。
## 语法
```sql
-CONCAT_WS ( <sep> , <str> [ , <str> ] )
-CONCAT_WS ( <sep> , <array> [ , <array> ])
+-- 字符串模式
+CONCAT_WS(<sep>, <str> [, <str> ...])
+
+-- 数组模式
+CONCAT_WS(<sep>, <array> [, <array> ...])
```
## 参数
| 参数 | 说明 |
|-------|-----------------|
-| `<sep>` | 用于拼接字符串的连接符,类型为 string 或 varchar |
-| `<str>` | 待拼接的字符串,类型为 string 或 varchar |
-| `<array>` | 待拼接的数组,类型为 ARRAY,且数组元素为 string 或 varchar |
-
+| `<sep>` | 分隔符字符串,用于连接各个部分。类型:VARCHAR |
+| `<str>` | 待连接的字符串参数。类型:VARCHAR |
+| `<array>` | 待连接的数组参数,数组元素必须为字符串类型。类型:ARRAY<VARCHAR> |
## 返回值
-参数 `<sep>` 或者 `<array>` 数组使用 `<str>` 拼接后字符串。特殊情况:
+返回 VARCHAR 类型,表示使用分隔符连接后的字符串。
-- 如果分隔符是 NULL,返回 NULL。
-- 如果多个数组参数中含有NULL参数,则返回空字符串
-## 举例
+连接规则:
+- 使用第一个参数作为分隔符连接后续参数
+- 自动跳过 NULL 值,但保留空字符串
+- 支持字符串参数或数组参数,但不能混合使用
+- 支持 UTF-8 多字节字符作为分隔符和内容
-将字符串通过 or 拼接到一起
+特殊情况:
+- 如果分隔符为 NULL,返回 NULL
+- 如果所有待连接的参数都是 NULL,返回空字符串
+- 数组模式中,跳过数组中的 NULL 元素,但保留空字符串元素
+- 多个数组参数中包含 NULL 数组时,返回空字符串
+- 不允许字符串参数和数组参数混合使用
+## 示例
+1. 基本字符串连接
```sql
-SELECT CONCAT_WS("or", "d", "is"),CONCAT_WS(NULL, "d", "is"),CONCAT_WS('or', 'd', NULL, 'is')
+SELECT CONCAT_WS(',', 'apple', 'banana', 'orange'), CONCAT_WS('-', 'hello', 'world');
```
-
```text
-+----------------------------+----------------------------+------------------------------------------+
-| concat_ws('or', 'd', 'is') | concat_ws(NULL, 'd', 'is') | concat_ws('or', 'd', NULL, 'is') |
-+----------------------------+----------------------------+------------------------------------------+
-| doris | NULL | doris |
-+----------------------------+----------------------------+------------------------------------------+
++-------------------------------------------+----------------------------------+
+| CONCAT_WS(',', 'apple', 'banana', 'orange') | CONCAT_WS('-', 'hello', 'world') |
++-------------------------------------------+----------------------------------+
+| apple,banana,orange | hello-world |
++-------------------------------------------+----------------------------------+
```
-将 array 数组通过 or 拼接到一起
-
+2. NULL 分隔符处理
```sql
-SELECT CONCAT_WS("or", ["d", "is"]),CONCAT_WS(NULL, ["d", "is"]),CONCAT_WS("or", ["d", NULL,"is"])
+SELECT CONCAT_WS(NULL, 'd', 'is'), CONCAT_WS('or', 'd', NULL, 'is');
```
-
```text
-+------------------------------+------------------------------+------------------------------------+
-| concat_ws('or', ['d', 'is']) | concat_ws(NULL, ['d', 'is']) | concat_ws('or', ['d', NULL, 'is']) |
-+------------------------------+------------------------------+------------------------------------+
-| doris | NULL | doris |
-+------------------------------+------------------------------+------------------------------------+
++----------------------------+----------------------------------+
+| CONCAT_WS(NULL, 'd', 'is') | CONCAT_WS('or', 'd', NULL, 'is') |
++----------------------------+----------------------------------+
+| NULL | doris |
++----------------------------+----------------------------------+
```
-拼接多个数组
+3. 空字符串处理(保留空字符串)
```sql
-mysql> SELECT CONCAT_WS("-", ["a", "b"], ["c", NULL], ["d"]);
-
-+------------------------------------------------+
-| CONCAT_WS("-", ["a", "b"], ["c", NULL], ["d"]) |
-+------------------------------------------------+
-| a-b-c-d |
-+------------------------------------------------+
+SELECT CONCAT_WS('|', 'hello', '', 'world', NULL), CONCAT_WS(',', '', 'test', '');
+```
+```text
++--------------------------------------------+-------------------------------+
+| CONCAT_WS('|', 'hello', '', 'world', NULL) | CONCAT_WS(',', '', 'test', '') |
++--------------------------------------------+-------------------------------+
+| hello||world | ,test, |
++--------------------------------------------+-------------------------------+
```
-如果在多个数组参数中包含NULL参数,则返回空字符串;
-
+4. 全部为 NULL 的情况
```sql
-mysql> SELECT CONCAT_WS("-", ["a", "b"], null,["c", NULL], ["d"]);
-+-----------------------------------------------------+
-| CONCAT_WS("-", ["a", "b"], null,["c", NULL], ["d"]) |
-+-----------------------------------------------------+
-| |
-+-----------------------------------------------------+
+SELECT CONCAT_WS('x', NULL, NULL), CONCAT_WS('-', NULL, NULL, NULL);
+```
+```text
++----------------------------+---------------------------------+
+| CONCAT_WS('x', NULL, NULL) | CONCAT_WS('-', NULL, NULL, NULL) |
++----------------------------+---------------------------------+
+| | |
++----------------------------+---------------------------------+
```
-处理空字符串
-
+5. 数组模式基本用法
```sql
-mysql> SELECT CONCAT_WS("|", "hello", "", "world", NULL);
-
-+--------------------------------------------+
-| CONCAT_WS("|", "hello", "", "world", NULL) |
-+--------------------------------------------+
-| hello||world |
-+--------------------------------------------+
+SELECT CONCAT_WS('or', ['d', 'is']), CONCAT_WS('-', ['apple', 'banana', 'cherry']);
+```
+```text
++------------------------------+--------------------------------------------+
+| CONCAT_WS('or', ['d', 'is']) | CONCAT_WS('-', ['apple', 'banana', 'cherry']) |
++------------------------------+--------------------------------------------+
+| doris | apple-banana-cherry |
++------------------------------+--------------------------------------------+
```
-混合字符串和数组(无效)
-
+6. 数组中的 NULL 值处理
```sql
-mysql> SELECT CONCAT_WS(",", "a", ["b", "c"]);
-
-ERROR 1105 (HY000): errCode = 2, detailMessage = can not cast from origin type ARRAY<VARCHAR(1)> to target type=VARCHAR(65533)
-
+SELECT CONCAT_WS('or', ['d', NULL, 'is']), CONCAT_WS(',', [NULL, 'a', 'b', NULL, 'c']);
+```
+```text
++------------------------------------+------------------------------------------+
+| CONCAT_WS('or', ['d', NULL, 'is']) | CONCAT_WS(',', [NULL, 'a', 'b', NULL, 'c']) |
++------------------------------------+------------------------------------------+
+| doris | a,b,c |
++------------------------------------+------------------------------------------+
```
-全为 NULL 的输入
-
- ```sql
- mysql> SELECT CONCAT_WS("x", NULL, NULL);
-
-+----------------------------+
-| CONCAT_WS("x", NULL, NULL) |
-+----------------------------+
-| |
-+----------------------------+
- ```
-
-Chiese Charactors concat
-
+7. 多个数组连接
```sql
-mysql> SELECT CONCAT_WS("x", '中文', '中文');
-
-+------------------------------------+
-| CONCAT_WS("x", '中文', '中文') |
-+------------------------------------+
-| 中文x中文 |
-+------------------------------------+
+SELECT CONCAT_WS('-', ['a', 'b'], ['c', NULL], ['d']), CONCAT_WS('|', ['x'], ['y', 'z']);
+```
+```text
++------------------------------------------------+----------------------------------+
+| CONCAT_WS('-', ['a', 'b'], ['c', NULL], ['d']) | CONCAT_WS('|', ['x'], ['y', 'z']) |
++------------------------------------------------+----------------------------------+
+| a-b-c-d | x|y|z |
++------------------------------------------------+----------------------------------+
```
-中文字符拼接
-
+8. 多个数组中包含 NULL 数组
```sql
-mysql> SELECT CONCAT_WS("x", ['中文'], ['中文']);
-+----------------------------------------+
-| CONCAT_WS("x", ['中文'], ['中文']) |
-+----------------------------------------+
-| 中文x中文 |
-+----------------------------------------+
+SELECT CONCAT_WS('-', ['a', 'b'], NULL, ['c', NULL], ['d']);
+```
+```text
++-----------------------------------------------------+
+| CONCAT_WS('-', ['a', 'b'], NULL, ['c', NULL], ['d']) |
++-----------------------------------------------------+
+| |
++-----------------------------------------------------+
```
-插入数据并拼接
-
+9. UTF-8 多字节字符处理
```sql
-DROP TABLE IF EXISTS test_concat_ws_1;
-
-CREATE TABLE test_concat_ws_1 (id INT, a ARRAY<VARCHAR>, b ARRAY<VARCHAR>) ENGINE=OLAP DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES ('replication_num' = '1')
-
-INSERT INTO test_concat_ws_1 VALUES (1, ['a','b'], ['css',null,'d']), (2, ['x',null], ['y','z']),(3,['你好','世界'],['Doris',null,'Nereids'])
-
-SELECT concat_ws('-', a, b) FROM test_concat_ws_1 ORDER BY id
-
+SELECT CONCAT_WS('x', 'ṭṛì', 'ḍḍumai'), CONCAT_WS('→', ['ṭṛì', 'ḍḍumai', 'hello']);
```
-
```text
++-------------------------------+----------------------------------------------+
+| CONCAT_WS('x', 'ṭṛì', 'ḍḍumai') | CONCAT_WS('→', ['ṭṛì', 'ḍḍumai', 'hello']) |
++-------------------------------+----------------------------------------------+
+| ṭṛìxḍḍumai | ṭṛì→ḍḍumai→hello |
++-------------------------------+----------------------------------------------+
+```
-+-----------------------------+
-| concat_ws('-', a, b) |
-+-----------------------------+
-| a-b-css-d |
-| x-y-z |
-| 你好-世界-Doris-Nereids |
-+-----------------------------+
+10. CSV 格式生成和路径拼接
+```sql
+SELECT CONCAT_WS(',', 'Name', 'Age', 'City'), CONCAT_WS('/', 'home', 'user', 'documents', 'file.txt');
+```
+```text
++------------------------------------+--------------------------------------------------------+
+| CONCAT_WS(',', 'Name', 'Age', 'City') | CONCAT_WS('/', 'home', 'user', 'documents', 'file.txt') |
++------------------------------------+--------------------------------------------------------+
+| Name,Age,City | home/user/documents/file.txt |
++------------------------------------+--------------------------------------------------------+
```
\ No newline at end of file
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/concat.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/concat.md
index b0cc85d1b24..593d2a95082 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/concat.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/concat.md
@@ -7,39 +7,130 @@
## 描述
-将多个字符串连接起来。特殊情况:
-
-- 如果参数中任意一个值是 NULL,那么返回的结果就是 NULL
-
+CONCAT 函数用于将多个字符串按顺序连接成一个字符串。该函数支持可变数量的参数,是字符串处理中最基本和常用的函数之一。在数据拼接、报表生成、动态 SQL 构建等场景中广泛使用。需要注意的是,如果任一参数为 NULL,整个结果都将为 NULL。
## 语法
```sql
-CONCAT ( <expr> [ , <expr> ... ] )
+CONCAT(<expr> [, <expr> ...])
```
## 参数
| 参数 | 说明 |
|----------|--------------|
-| `<expr>` | 需要被连接到一起的字符串 |
+| `<expr>` | 需要连接的字符串表达式,可以是字符串常量、列名或其他表达式。类型:VARCHAR |
## 返回值
-参数列表 `<expr>` 连接到一起的字符串。特殊情况:
+返回 VARCHAR 类型,表示所有参数连接后的字符串。
+
+连接规则:
+- 按参数顺序依次连接字符串
+- 支持任意数量的参数(至少1个)
+- 支持 UTF-8 多字节字符的正确连接
+- 数字和其他类型会自动转换为字符串
-- 如果参数中任意一个值是 NULL,那么返回的结果就是 NULL
+特殊情况:
+- 如果任一参数为 NULL,返回 NULL(这是与 CONCAT_WS 的主要区别)
+- 如果没有参数,语法错误
+- 空字符串参数不影响连接结果
+- 支持与非字符串类型混合使用
-## 举例
+## 示例
+
+1. 基本字符串连接
+```sql
+SELECT CONCAT('a', 'b'), CONCAT('a', 'b', 'c');
+```
+```text
++------------------+-----------------------+
+| CONCAT('a', 'b') | CONCAT('a', 'b', 'c') |
++------------------+-----------------------+
+| ab | abc |
++------------------+-----------------------+
+```
+2. NULL 值处理(关键特性)
```sql
-SELECT CONCAT("a", "b"),CONCAT("a", "b", "c"),CONCAT("a", null, "c")
+SELECT CONCAT('a', NULL, 'c'), CONCAT('hello', NULL);
+```
+```text
++------------------------+---------------------+
+| CONCAT('a', NULL, 'c') | CONCAT('hello', NULL) |
++------------------------+---------------------+
+| NULL | NULL |
++------------------------+---------------------+
```
+3. 空字符串处理
+```sql
+SELECT CONCAT('hello', '', 'world'), CONCAT('', 'test', '');
+```
+```text
++-----------------------------+------------------------+
+| CONCAT('hello', '', 'world') | CONCAT('', 'test', '') |
++-----------------------------+------------------------+
+| helloworld | test |
++-----------------------------+------------------------+
+```
+
+4. 数字与字符串混合
+```sql
+SELECT CONCAT('User', 123), CONCAT('Price: $', 99.99);
+```
+```text
++---------------------+---------------------------+
+| CONCAT('User', 123) | CONCAT('Price: $', 99.99) |
++---------------------+---------------------------+
+| User123 | Price: $99.99 |
++---------------------+---------------------------+
+```
+
+5. 多个参数连接
+```sql
+SELECT CONCAT('A', 'B', 'C', 'D', 'E'), CONCAT('1', '2', '3', '4', '5');
+```
+```text
++----------------------------------+----------------------------------+
+| CONCAT('A', 'B', 'C', 'D', 'E') | CONCAT('1', '2', '3', '4', '5') |
++----------------------------------+----------------------------------+
+| ABCDE | 12345 |
++----------------------------------+----------------------------------+
+```
+
+6. UTF-8 多字节字符连接
+```sql
+SELECT CONCAT('ṭṛì', ' ', 'ḍḍumai'), CONCAT('Hello', ' ', 'ṭṛì', ' ', 'ḍḍumai');
+```
+```text
++------------------------------+--------------------------------------+
+| CONCAT('ṭṛì', ' ', 'ḍḍumai') | CONCAT('Hello', ' ', 'ṭṛì', ' ', 'ḍḍumai') |
++------------------------------+--------------------------------------+
+| ṭṛì ḍḍumai | Hello ṭṛì ḍḍumai |
++------------------------------+--------------------------------------+
+```
+
+7. 路径和URL构建
+```sql
+SELECT CONCAT('/home/', 'user/', 'file.txt'), CONCAT('https://', 'www.example.com', '/api');
+```
+```text
++--------------------------------------+----------------------------------------------+
+| CONCAT('/home/', 'user/', 'file.txt') | CONCAT('https://', 'www.example.com', '/api') |
++--------------------------------------+----------------------------------------------+
+| /home/user/file.txt | https://www.example.com/api |
++--------------------------------------+----------------------------------------------+
+```
+
+8. 电子邮件地址构建
+```sql
+SELECT CONCAT('user', '@', 'example.com'), CONCAT('admin.', 'support', '@', 'company.org');
+```
```text
-+------------------+-----------------------+------------------------+
-| concat('a', 'b') | concat('a', 'b', 'c') | concat('a', NULL, 'c') |
-+------------------+-----------------------+------------------------+
-| ab | abc | NULL |
-+------------------+-----------------------+------------------------+
++------------------------------------+-----------------------------------------------+
+| CONCAT('user', '@', 'example.com') | CONCAT('admin.', 'support', '@', 'company.org') |
++------------------------------------+-----------------------------------------------+
+| user@example.com | admin.support@company.org |
++------------------------------------+-----------------------------------------------+
```
\ No newline at end of file
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/count_substrings.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/count_substrings.md
index f8c4de3ab3f..708549b3915 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/count_substrings.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/count_substrings.md
@@ -96,26 +96,26 @@ SELECT count_substrings('a,b,c,abcde', '');
6. 使用起始位置参数
```sql
-SELECT count_substrings('你好,世界!你好,世界!', '世界', 1),
- count_substrings('你好,世界!你好,世界!', '世界', 6);
+SELECT count_substrings('ṭṛì ḍḍumai ṭṛì ti ḍḍumannàri', 'ḍḍu', 1),
+ count_substrings('ṭṛì ḍḍumai ṭṛì ti ḍḍumannàri', 'ḍḍu', 6);
```
```text
-+-----------------------------------------------------------------------+-----------------------------------------------------------------------+
-| count_substrings('你好,世界!你好,世界!', '世界', 1) | count_substrings('你好,世界!你好,世界!', '世界', 6) |
-+-----------------------------------------------------------------------+-----------------------------------------------------------------------+
-| 2 | 1 |
-+-----------------------------------------------------------------------+-----------------------------------------------------------------------+
++-----------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+
+| count_substrings('ṭṛì ḍḍumai ṭṛì ti ḍḍumannàri', 'ḍḍu', 1) | count_substrings('ṭṛì ḍḍumai ṭṛì ti ḍḍumannàri', 'ḍḍu', 6) |
++-----------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+
+| 2 | 1 |
++-----------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+
```
7. 起始位置超出范围
```sql
-SELECT count_substrings('你好,世界!你好,世界!', '世界', 0),
- count_substrings('你好,世界!你好,世界!', '世界', 30);
+SELECT count_substrings('éèêëìíîïðñòó éèêëìíîïðñòó', 'éèê', 0),
+ count_substrings('éèêëìíîïðñòó éèêëìíîïðñòó', 'éèê', 30);
```
```text
-+-----------------------------------------------------------------------+------------------------------------------------------------------------+
-| count_substrings('你好,世界!你好,世界!', '世界', 0) | count_substrings('你好,世界!你好,世界!', '世界', 30) |
-+-----------------------------------------------------------------------+------------------------------------------------------------------------+
-| 0 | 0 |
-+-----------------------------------------------------------------------+------------------------------------------------------------------------+
++------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+
+| count_substrings('éèêëìíîïðñòó éèêëìíîïðñòó', 'éèê', 0) | count_substrings('éèêëìíîïðñòó éèêëìíîïðñòó', 'éèê', 30) |
++------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+
+| 0 | 0 |
++------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------+
```
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/digital-masking.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/digital-masking.md
index c2c67a7a9e5..f2b91c174ee 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/digital-masking.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/digital-masking.md
@@ -7,34 +7,87 @@
## 描述
-`digital_masking` 函数用于对数字进行脱敏处理。根据指定的脱敏规则,将数字的部分字符替换为 * 。别名函数,原始函数为 `concat(left(id,3),'****',right(id,4))`。
+DIGITAL_MASKING 函数用于对数字字符串进行脱敏处理。按照固定格式将数字的中间部分替换为 `****`,保留前3位和后4位。等价于 `CONCAT(LEFT(id, 3), '****', RIGHT(id, 4))`。
## 语法
```sql
-DIGITAL_MASKING( <digital_number> )
+DIGITAL_MASKING(<digital_number>)
```
## 参数
| 参数 | 说明 |
-| -- | -- |
-| `<digital_number>` | 需要脱敏的数字字符串 |
+| ------------------ | ----------------------------------------- |
+| `<digital_number>` | 需要脱敏的数字字符串。类型:VARCHAR |
## 返回值
-返回脱敏后的数字字符串。
+返回 VARCHAR 类型,为脱敏后的数字字符串。
-## 举例
+特殊情况:
+- 如果参数为 NULL,返回 NULL
+- 脱敏格式为:前3位 + `****` + 后4位
+- 字符串长度不足7位时,结果可能重叠
+## 示例
+
+1. 基本用法:11位手机号脱敏
+```sql
+SELECT digital_masking('13812345678');
+```
+```text
++--------------------------------+
+| digital_masking('13812345678') |
++--------------------------------+
+| 138****5678 |
++--------------------------------+
+```
+
+2. 不同长度的数字
+```sql
+SELECT digital_masking('1234567890');
+```
+```text
++-------------------------------+
+| digital_masking('1234567890') |
++-------------------------------+
+| 123****7890 |
++-------------------------------+
+```
+
+3. 短数字(少于7位)
+```sql
+SELECT digital_masking('123');
+```
+```text
++------------------------+
+| digital_masking('123') |
++------------------------+
+| 123****123 |
++------------------------+
+```
+
+4. NULL 值处理
```sql
-select digital_masking(13812345678);
+SELECT digital_masking(NULL);
+```
+```text
++-----------------------+
+| digital_masking(NULL) |
++-----------------------+
+| NULL |
++-----------------------+
```
+5. 带有 utf-8 的字符串
+```sql
+SELECT digital_masking('13812ṭṛ34678');
+```
```text
-+------------------------------+
-| digital_masking(13812345678) |
-+------------------------------+
-| 138****5678 |
-+------------------------------+
-```
\ No newline at end of file
++-------------------------------------+
+| digital_masking('13812ṭṛ34678') |
++-------------------------------------+
+| 138****4678 |
++-------------------------------------+
+````
\ No newline at end of file
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/elt.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/elt.md
index f3fd7eda8fa..382ffa35c16 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/elt.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/elt.md
@@ -7,39 +7,133 @@
## 描述
-在指定的索引处返回一个字符串。特殊情况:
-
-- 如果指定的索引处没有字符串,则返回 NULL。
+ELT 函数根据指定的索引位置返回对应的字符串。索引从1开始计数。
## 语法
```sql
-ELT ( <pos> , <str> [ , <str> ] )
+ELT(<pos>, <str>[, <str> ...])
```
## 参数
-| 参数 | 说明 |
-|---------|------------|
-| `<pos>` | 指定的索引值 |
-| `<str>` | 需要指定索引的字符串 |
+| 参数 | 说明 |
+| -------- | ----------------------------------------- |
+| `<pos>` | 索引位置(从1开始)。类型:INT |
+| `<str>` | 字符串列表。类型:VARCHAR |
## 返回值
-参数 `<str>` 指定索引值的字符串。特殊情况:
+返回 VARCHAR 类型,为指定索引位置的字符串。
+
+特殊情况:
+- 如果 `<pos>` 小于1或大于字符串数量,返回 NULL
+- 如果 `<pos>` 为 NULL,返回 NULL
+- 索引从1开始,第一个字符串的索引为1
+
+## 示例
+
+1. 基本用法:获取第1个字符串
+```sql
+SELECT ELT(1, 'aaa', 'bbb', 'ccc');
+```
+```text
++-----------------------------+
+| elt(1, 'aaa', 'bbb', 'ccc') |
++-----------------------------+
+| aaa |
++-----------------------------+
+```
+
+2. 获取第2个字符串
+```sql
+SELECT ELT(2, 'aaa', 'bbb', 'ccc');
+```
+```text
++-----------------------------+
+| elt(2, 'aaa', 'bbb', 'ccc') |
++-----------------------------+
+| bbb |
++-----------------------------+
+```
+
+3. 索引越界返回 NULL
+```sql
+SELECT ELT(0, 'aaa', 'bbb'), ELT(5, 'aaa', 'bbb');
+```
+```text
++----------------------+----------------------+
+| elt(0, 'aaa', 'bbb') | elt(5, 'aaa', 'bbb') |
++----------------------+----------------------+
+| NULL | NULL |
++----------------------+----------------------+
+```
+
+4. NULL 值处理
+```sql
+SELECT ELT(NULL, 'aaa', 'bbb');
+```
+```text
++-------------------------+
+| elt(NULL, 'aaa', 'bbb') |
++-------------------------+
+| NULL |
++-------------------------+
+```
+
+4. 索引超出范围返回 NULL
+
+```sql
+SELECT ELT(5, 'aaa', 'bbb', 'ccc');
+```
+
+```text
++-----------------------------+
+| elt(5, 'aaa', 'bbb', 'ccc') |
++-----------------------------+
+| NULL |
++-----------------------------+
+```
+
+5. 负数索引返回 NULL
+
+```sql
+SELECT ELT(-1, 'first', 'second');
+```
+
+```text
++----------------------------+
+| elt(-1, 'first', 'second') |
++----------------------------+
+| NULL |
++----------------------------+
+```
-- 如果指定的索引处没有字符串,则返回 NULL。
+6. utf-8 字符串
-## 举例
+```sql
+SELECT
+ ELT(2, 'Hello', 'ṭṛ', 'Hola');
+```
+
+```text
++-----------------------------------+
+| ELT(2, 'Hello', 'ṭṛ', 'Hola') |
++-----------------------------------+
+| ṭṛ |
++-----------------------------------+
+```
+
+7. 处理空字符串
```sql
-SELECT ELT(1, 'aaa', 'bbb'),ELT(2, 'aaa', 'bbb'), ELT(0, 'aaa', 'bbb'),ELT(2, 'aaa', 'bbb')
+SELECT ELT(2, 'first', '', 'third');
```
```text
-+----------------------+----------------------+----------------------+----------------------+
-| elt(1, 'aaa', 'bbb') | elt(2, 'aaa', 'bbb') | elt(0, 'aaa', 'bbb') | elt(2, 'aaa', 'bbb') |
-+----------------------+----------------------+----------------------+----------------------+
-| aaa | bbb | NULL | bbb |
-+----------------------+----------------------+----------------------+----------------------+
-```
\ No newline at end of file
++------------------------------+
+| elt(2, 'first', '', 'third') |
++------------------------------+
+| |
++------------------------------+
+```
diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/ends-with.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/ends-with.md
index 88d8a80a223..c8d8e6feb1c 100644
--- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/ends-with.md
+++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/string-functions/ends-with.md
@@ -7,39 +7,155 @@
## 描述
-如果字符串以指定后缀结尾则返回 true,否则返回 false。特殊情况:
-
-- 两个参数任意一个参数为 NULL,返回 NULL。
+ENDS_WITH 函数用于检查字符串是否以指定的后缀结尾。
## 语法
```sql
... 7889 lines suppressed ...
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org