Add some string functions document (#928)
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
# ascii
|
||||
|
||||
## Description
|
||||
|
||||
返回字符串第一个字符串对应的ascii 码
|
||||
|
||||
## Syntax
|
||||
|
||||
`INT ascii(VARCHAR)`
|
||||
`INT ascii(VARCHAR str)`
|
||||
|
||||
## Description
|
||||
|
||||
返回字符串第一个字符对应的 ascii 码
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
# concat
|
||||
|
||||
## Description
|
||||
|
||||
将多个字符串连接起来, 如果参数中任意一个值是NULL,那么返回的结果就是NULL
|
||||
|
||||
## Syntax
|
||||
|
||||
`VARCHAR concat(VARCHAR,...)`
|
||||
|
||||
## Description
|
||||
|
||||
将多个字符串连接起来, 如果参数中任意一个值是 NULL,那么返回的结果就是 NULL
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
# concat_ws
|
||||
|
||||
## Description
|
||||
|
||||
使用第一个参数作为连接符,将第二个参数以及后续所有参数拼接成一个字符串.
|
||||
如果分隔符是NULL,返回NULL。
|
||||
`concat_ws`函数不会跳过空字符串,会跳过NULL值
|
||||
|
||||
## Syntax
|
||||
|
||||
`VARCHAR concat_ws(VARCHAR, VARCHAR,...)`
|
||||
`VARCHAR concat_ws(VARCHAR sep, VARCHAR str,...)`
|
||||
|
||||
## Description
|
||||
|
||||
使用第一个参数 sep 作为连接符,将第二个参数以及后续所有参数拼接成一个字符串.
|
||||
如果分隔符是 NULL,返回 NULL。
|
||||
`concat_ws`函数不会跳过空字符串,会跳过 NULL 值
|
||||
|
||||
## Examples
|
||||
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
# find_in_set
|
||||
|
||||
## Syntax
|
||||
|
||||
`INT find_in_set(VARCHAR str, VARCHAR strlist)`
|
||||
|
||||
## Description
|
||||
|
||||
返回 strlist 中第一次出现 str 的位置(从1开始计数)。strlist 是用逗号分隔的字符串。如果没有找到,返回0。任意参数为 NULL ,返回 NULL。
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
mysql> select find_in_set("b", "a,b,c");
|
||||
+---------------------------+
|
||||
| find_in_set('b', 'a,b,c') |
|
||||
+---------------------------+
|
||||
| 2 |
|
||||
+---------------------------+
|
||||
```
|
||||
@ -0,0 +1,36 @@
|
||||
# group_concat
|
||||
|
||||
## Syntax
|
||||
|
||||
`VARCHAR group_concat(VARCHAR str[, VARCHAR sep])`
|
||||
|
||||
## Description
|
||||
|
||||
该函数是类似于 sum() 的聚合函数,group_concat 将结果集中的多行结果连接成一个字符串。第二个参数 sep 为字符串之间的连接符号,该参数可以省略。该函数通常需要和 group by 语句一起使用。
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
mysql> select value from test;
|
||||
+-------+
|
||||
| value |
|
||||
+-------+
|
||||
| a |
|
||||
| b |
|
||||
| c |
|
||||
+-------+
|
||||
|
||||
mysql> select group_concat(value) from test;
|
||||
+-----------------------+
|
||||
| group_concat(`value`) |
|
||||
+-----------------------+
|
||||
| a, b, c |
|
||||
+-----------------------+
|
||||
|
||||
mysql> select group_concat(value, " ") from test;
|
||||
+----------------------------+
|
||||
| group_concat(`value`, ' ') |
|
||||
+----------------------------+
|
||||
| a b c |
|
||||
+----------------------------+
|
||||
```
|
||||
@ -0,0 +1,27 @@
|
||||
# instr
|
||||
|
||||
## Syntax
|
||||
|
||||
`INT instr(VARCHAR str, VARCHAR substr)`
|
||||
|
||||
## Description
|
||||
|
||||
返回 substr 在 str 中第一次出现的位置(从1开始计数)。如果 substr 不在 str 中出现,则返回0。
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
mysql> select instr("abc", "b");
|
||||
+-------------------+
|
||||
| instr('abc', 'b') |
|
||||
+-------------------+
|
||||
| 2 |
|
||||
+-------------------+
|
||||
|
||||
mysql> select instr("abc", "d");
|
||||
+-------------------+
|
||||
| instr('abc', 'd') |
|
||||
+-------------------+
|
||||
| 0 |
|
||||
+-------------------+
|
||||
```
|
||||
@ -0,0 +1,10 @@
|
||||
# lcase
|
||||
|
||||
## Syntax
|
||||
|
||||
`INT lcase(VARCHAR str)`
|
||||
|
||||
## Description
|
||||
|
||||
与`lower`一致
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
# length
|
||||
|
||||
## Syntax
|
||||
|
||||
`INT length(VARCHAR str)`
|
||||
|
||||
## Description
|
||||
|
||||
返回字符串的长度,对于多字节字符,返回的字符数。比如5个两字节宽度字,返回的长度是10。
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
mysql> select length("abc");
|
||||
+---------------+
|
||||
| length('abc') |
|
||||
+---------------+
|
||||
| 3 |
|
||||
+---------------+
|
||||
|
||||
mysql> select length("中国");
|
||||
+------------------+
|
||||
| length('中国') |
|
||||
+------------------+
|
||||
| 6 |
|
||||
+------------------+
|
||||
```
|
||||
@ -0,0 +1,34 @@
|
||||
# locate
|
||||
|
||||
## Syntax
|
||||
|
||||
`INT locate(VARCHAR substr, VARCHAR str[, INT pos])`
|
||||
|
||||
## Description
|
||||
|
||||
返回 substr 在 str 中出现的位置(从1开始计数)。如果指定第3个参数 pos,则从 str 以 pos 下标开始的字符串处开始查找 substr 出现的位置。如果没有找到,返回0
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
mysql> SELECT LOCATE('bar', 'foobarbar');
|
||||
+----------------------------+
|
||||
| locate('bar', 'foobarbar') |
|
||||
+----------------------------+
|
||||
| 4 |
|
||||
+----------------------------+
|
||||
|
||||
mysql> SELECT LOCATE('xbar', 'foobar');
|
||||
+--------------------------+
|
||||
| locate('xbar', 'foobar') |
|
||||
+--------------------------+
|
||||
| 0 |
|
||||
+--------------------------+
|
||||
|
||||
mysql> SELECT LOCATE('bar', 'foobarbar', 5);
|
||||
+-------------------------------+
|
||||
| locate('bar', 'foobarbar', 5) |
|
||||
+-------------------------------+
|
||||
| 7 |
|
||||
+-------------------------------+
|
||||
```
|
||||
@ -0,0 +1,20 @@
|
||||
# lower
|
||||
|
||||
## Syntax
|
||||
|
||||
`INT lower(VARCHAR str)`
|
||||
|
||||
## Description
|
||||
|
||||
将参数中所有的字符串都转换成小写
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
mysql> SELECT lower("AbC123");
|
||||
+-----------------+
|
||||
| lower('AbC123') |
|
||||
+-----------------+
|
||||
| abc123 |
|
||||
+-----------------+
|
||||
```
|
||||
@ -0,0 +1,27 @@
|
||||
# lpad
|
||||
|
||||
## Syntax
|
||||
|
||||
`VARCHAR lpad(VARCHAR str, INT len, VARCHAR pad)`
|
||||
|
||||
## Description
|
||||
|
||||
返回 str 中长度为 len(从首字母开始算起)的字符串。如果 len 大于 str 的长度,则在 str 的前面不断补充 pad 字符,直到该字符串的长度达到 len 为止。如果 len 小于 str 的长度,该函数相当于截断 str 字符串,只返回长度为 len 的字符串。
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
mysql> SELECT lpad("hi", 5, "xy");
|
||||
+---------------------+
|
||||
| lpad('hi', 5, 'xy') |
|
||||
+---------------------+
|
||||
| xyxhi |
|
||||
+---------------------+
|
||||
|
||||
mysql> SELECT lpad("hi", 1, "xy");
|
||||
+---------------------+
|
||||
| lpad('hi', 1, 'xy') |
|
||||
+---------------------+
|
||||
| h |
|
||||
+---------------------+
|
||||
```
|
||||
@ -0,0 +1,20 @@
|
||||
# ltrim
|
||||
|
||||
## Syntax
|
||||
|
||||
`VARCHAR ltrim(VARCHAR str)`
|
||||
|
||||
## Description
|
||||
|
||||
将参数 str 中从开始部分连续出现的空格去掉
|
||||
|
||||
## Examples
|
||||
|
||||
```
|
||||
mysql> SELECT ltrim(' ab d');
|
||||
+------------------+
|
||||
| ltrim(' ab d') |
|
||||
+------------------+
|
||||
| ab d |
|
||||
+------------------+
|
||||
```
|
||||
Reference in New Issue
Block a user