Skip to content

Commit

Permalink
[doc](function) opt string function doc (apache#1849)
Browse files Browse the repository at this point in the history
## Versions 

- [x] dev
- [x] 3.0
- [x] 2.1
- [ ] 2.0

## Languages

- [x] Chinese
- [x] English

## Docs Checklist

- [ ] Checked by AI
- [ ] Test Cases Built

---------

Co-authored-by: smallhibiscus <844981280>
  • Loading branch information
smallhibiscus authored and echo-hhj committed Jan 23, 2025
1 parent 4fe4343 commit 8bc2f44
Show file tree
Hide file tree
Showing 138 changed files with 4,431 additions and 2,745 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,37 @@ specific language governing permissions and limitations
under the License.
-->

## append_trailing_char_if_absent
## Description

### 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.

#### Syntax
## Syntax

`VARCHAR append_trailing_char_if_absent(VARCHAR str, VARCHAR trailing_char)`
```sql
APPEND_TRAILING_CHAR_IF_ABSENT ( <str> , <trailing_char> )
```

If the @str string is non-empty and does not contain the @trailing_char character at the end, it appends the @trailing_char character to the end.
@trailing_char contains only one character, and it will return NULL if contains more than one character
## Parameters

### example
| 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) |

```
MySQL [test]> select append_trailing_char_if_absent('a','c');
+------------------------------------------+
| append_trailing_char_if_absent('a', 'c') |
+------------------------------------------+
| ac |
+------------------------------------------+
1 row in set (0.02 sec)
MySQL [test]> select append_trailing_char_if_absent('ac','c');
+-------------------------------------------+
| append_trailing_char_if_absent('ac', 'c') |
+-------------------------------------------+
| ac |
+-------------------------------------------+
1 row in set (0.00 sec)
```
## Return value

Parameters The string after concatenation of `<str>` and `<trailing_char>` (if `<trailing_char>` does not exist in `<str>`)

### keywords
## Example

APPEND_TRAILING_CHAR_IF_ABSENT
``` sql
SELECT APPEND_TRAILING_CHAR_IF_ABSENT('a','c'),APPEND_TRAILING_CHAR_IF_ABSENT('ac', 'c'),APPEND_TRAILING_CHAR_IF_ABSENT('ac', 'cd')
```

```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 |
+------------------------------------------+-------------------------------------------+--------------------------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,36 @@ specific language governing permissions and limitations
under the License.
-->

## ascii
### Description
#### Syntax
## Description

`INT AXES (WARCHAR STR)`
Returns the ASCII code of the first character of a string

## Syntax

Returns the ASCII code corresponding to the first character of the string
```sql
ASCII ( <str> )
```

### example
## Parameters

| Parameter | Description |
|-----------|-------------------------|
| `<str>` | The string whose ASCII code of the first character needs to be calculated |

## Return value

Parameter <str> ASCII code of the first character

## Example

```sql
SELECT ASCII('1'),ASCII('234')
```
mysql> select ascii('1');
+------------+
| ascii('1') |
+------------+
| 49 |
+------------+
mysql> select ascii('234');
+--------------+
| ascii('234') |
+--------------+
| 50 |
+--------------+
```
### keywords
ASCII

```text
+------------+--------------+
| ascii('1') | ascii('234') |
+------------+--------------+
| 49 | 50 |
+------------+--------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,42 @@ specific language governing permissions and limitations
under the License.
-->

## char_length
### Description
#### Syntax
## Description

INT char_length(VARCHAR str)
Calculates the length of a string. For multi-byte characters, returns the number of characters.

Currently only supports `utf8` encoding

Returns the length of the string, and the number of characters returned for multi-byte characters. For example, five two-byte width words return a length of 5, only utf8 encoding is support at the current version. `character_length` is the alias for this function.
## Alias

### example
- CHARACTER_LENGTH

## Syntax

```sql
CHAR_LENGTH ( <str> )
```
mysql> select char_length("abc");
+--------------------+
| char_length('abc') |
+--------------------+
| 3 |
+--------------------+
mysql> select char_length("中国");
+------------------- ---+
| char_length('中国') |
+-----------------------+
| 2 |
+-----------------------+

## Parameters

| Parameter | Description |
|-----------|------------|
| `<str>` | The string to calculate the length of |

## Return value

The length of the string <str>.

## Example

```sql
select CHAR_LENGTH("abc"),CHAR_LENGTH("中国")
```
### keywords
CHAR_LENGTH, CHARACTER_LENGTH

```text
+-------------------------+----------------------------+
| character_length('abc') | character_length('中国') |
+-------------------------+----------------------------+
| 3 | 2 |
+-------------------------+----------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,53 @@ specific language governing permissions and limitations
under the License.
-->

## Description

## function char
### description
#### Syntax
Interpret each argument as an integer and return a string consisting of the characters given by the code values ​​of those integers. Special cases:

`VARCHAR char(INT,..., [USING charset_name])`
- If the result string is illegal for the given character set, the corresponding conversion result is NULL.

Interprets each argument as an integer and returns a string consisting of the characters given by the code values of those integers. `NULL` values are skipped.
- Arguments greater than `255` are converted to multiple result bytes. For example, `char(15049882)` is equivalent to `char(229, 164, 154)`.

If the result string is illegal for the given character set, the result from `CHAR()` becomes `NULL`.
## Description

Arguments larger than `255` are converted into multiple result bytes. For example, `char(15049882)` is equivalent to `char(229, 164, 154)`.
Interpret each argument as an integer and return a string consisting of the characters given by the code values ​​of those integers. Special cases:

Currently only `utf8` is supported for `charset_name`.
- If the result string is illegal for the given character set, the corresponding conversion results in the value NULL.

### example
- Arguments greater than `255` are converted to multiple result bytes. For example, `char(15049882)` is equivalent to `char(229, 164, 154)`.

## Syntax

```sql
CHAR ( <expr> [ , <expr> ... ] [ USING <charset_name> ] )
```
mysql> select char(68, 111, 114, 105, 115);
+--------------------------------------+
| char('utf8', 68, 111, 114, 105, 115) |
+--------------------------------------+
| Doris |
+--------------------------------------+
mysql> select char(15049882, 15179199, 14989469);
+--------------------------------------------+
| char('utf8', 15049882, 15179199, 14989469) |
+--------------------------------------------+
| 多睿丝 |
+--------------------------------------------+
mysql> select char(255);
+-------------------+
| char('utf8', 255) |
+-------------------+
| NULL |
+-------------------+

## Parameters

| Parameters | Description |
|------------------|---------------------|
| `<expr>` | Integer to be calculated as a character |
| `<charset_name>` | Encoding of the return value, currently only supports `utf8` |

## Return value

Parameter list `<expr>` A string consisting of the corresponding characters. Special cases:

- If the result string is illegal for the given character set, the corresponding conversion result is NULL.

- Parameters greater than `255` will be converted to multiple result bytes. For example, `CHAR(15049882)` is equivalent to `CHAR(229, 164, 154)`.

## Example

```sql
SELECT CHAR(68, 111, 114, 105, 115),CHAR(15049882, 15179199, 14989469),CHAR(255)
```
### keywords
CHAR

```text
+--------------------------------------+--------------------------------------------+-------------------+
| char('utf8', 68, 111, 114, 105, 115) | char('utf8', 15049882, 15179199, 14989469) | char('utf8', 255) |
+--------------------------------------+--------------------------------------------+-------------------+
| Doris | 多睿丝 | NULL |
+--------------------------------------+--------------------------------------------+-------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,63 +24,61 @@ specific language governing permissions and limitations
under the License.
-->

## concat_ws
### Description
#### Syntax
## Description

Use the first parameter sep as the connector to concatenate the second parameter and all subsequent parameters (or all strings in ARRAY) into a string. Special cases:

- If the separator is NULL, NULL is returned.

The `CONCAT_WS` function does not skip empty strings, but skips NULL values.

## Syntax

```sql
VARCHAR concat_ws(VARCHAR sep, VARCHAR str,...)
VARCHAR concat_ws(VARCHAR sep, ARRAY array)
CONCAT_WS ( <sep> , <str> [ , <str> ] )
CONCAT_WS ( <sep> , <array> )
```

Using the first parameter SEP as a connector, the second parameter and all subsequent parameters(or all string in an ARRAY) are spliced into a string.
If the separator is NULL, return NULL.
The `concat_ws` function does not skip empty strings, it skips NULL values.
## Parameters

| Parameter | Description |
|-------|-----------------|
| `<sep>` | Connector for concatenating strings |
| `<str>` | String to be concatenated |
| `<array>` | Array to be concatenated |

## Return value

Parameter `<sep>` or `<array>` The string concatenated with `<str>`. Special cases:

- If delimiter is NULL, returns NULL.

### example
## Example

Concatenate strings together using or

```sql
SELECT CONCAT_WS("or", "d", "is"),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 |
+----------------------------+----------------------------+------------------------------------------+
```
mysql> select concat_ws("or", "d", "is");
+----------------------------+
| concat_ws('or', 'd', 'is') |
+----------------------------+
| doris |
+----------------------------+
mysql> select concat_ws(NULL, "d", "is");
+----------------------------+
| concat_ws(NULL, 'd', 'is') |
+----------------------------+
| NULL |
+----------------------------+
mysql> select concat_ws("or", "d", NULL,"is");
+---------------------------------+
| concat_ws("or", "d", NULL,"is") |
+---------------------------------+
| doris |
+---------------------------------+
mysql> select concat_ws("or", ["d", "is"]);
+-----------------------------------+
| concat_ws('or', ARRAY('d', 'is')) |
+-----------------------------------+
| doris |
+-----------------------------------+
mysql> select concat_ws(NULL, ["d", "is"]);
+-----------------------------------+
| concat_ws(NULL, ARRAY('d', 'is')) |
+-----------------------------------+
| NULL |
+-----------------------------------+
mysql> select concat_ws("or", ["d", NULL,"is"]);
+-----------------------------------------+
| concat_ws('or', ARRAY('d', NULL, 'is')) |
+-----------------------------------------+
| doris |
+-----------------------------------------+

Concatenate array arrays together using or

```sql
SELECT CONCAT_WS("or", ["d", "is"]),CONCAT_WS(NULL, ["d", "is"]),CONCAT_WS("or", ["d", NULL,"is"])
```
### keywords
CONCAT_WS,CONCAT,WS,ARRAY

```text
+------------------------------+------------------------------+------------------------------------+
| concat_ws('or', ['d', 'is']) | concat_ws(NULL, ['d', 'is']) | concat_ws('or', ['d', NULL, 'is']) |
+------------------------------+------------------------------+------------------------------------+
| doris | NULL | doris |
+------------------------------+------------------------------+------------------------------------+
```
Loading

0 comments on commit 8bc2f44

Please sign in to comment.