From cdd613c5a45cbabe3b70f5bc502e7bf48d0bb18b Mon Sep 17 00:00:00 2001 From: ZHAO Chun Date: Tue, 16 Apr 2019 10:14:49 +0800 Subject: [PATCH] Add some string functions document (#928) --- .../sql-functions/string-functions/ascii.md | 10 +++--- .../sql-functions/string-functions/concat.md | 8 ++--- .../string-functions/concat_ws.md | 14 ++++---- .../string-functions/find_in_set.md | 20 +++++++++++ .../string-functions/group_concat.md | 36 +++++++++++++++++++ .../sql-functions/string-functions/instr.md | 27 ++++++++++++++ .../sql-functions/string-functions/lcase.md | 10 ++++++ .../sql-functions/string-functions/length.md | 27 ++++++++++++++ .../sql-functions/string-functions/locate.md | 34 ++++++++++++++++++ .../sql-functions/string-functions/lower.md | 20 +++++++++++ .../sql-functions/string-functions/lpad.md | 27 ++++++++++++++ .../sql-functions/string-functions/ltrim.md | 20 +++++++++++ 12 files changed, 237 insertions(+), 16 deletions(-) create mode 100644 docs/documentation/cn/sql-reference/sql-functions/string-functions/find_in_set.md create mode 100644 docs/documentation/cn/sql-reference/sql-functions/string-functions/group_concat.md create mode 100644 docs/documentation/cn/sql-reference/sql-functions/string-functions/instr.md create mode 100644 docs/documentation/cn/sql-reference/sql-functions/string-functions/lcase.md create mode 100644 docs/documentation/cn/sql-reference/sql-functions/string-functions/length.md create mode 100644 docs/documentation/cn/sql-reference/sql-functions/string-functions/locate.md create mode 100644 docs/documentation/cn/sql-reference/sql-functions/string-functions/lower.md create mode 100644 docs/documentation/cn/sql-reference/sql-functions/string-functions/lpad.md create mode 100644 docs/documentation/cn/sql-reference/sql-functions/string-functions/ltrim.md diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/ascii.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/ascii.md index 2b45dc2f8b..95debfd84a 100644 --- a/docs/documentation/cn/sql-reference/sql-functions/string-functions/ascii.md +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/ascii.md @@ -1,12 +1,12 @@ # ascii -## Description - -返回字符串第一个字符串对应的ascii 码 - ## Syntax -`INT ascii(VARCHAR)` +`INT ascii(VARCHAR str)` + +## Description + +返回字符串第一个字符对应的 ascii 码 ## Examples diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/concat.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/concat.md index efd22dd28e..92ba559f61 100644 --- a/docs/documentation/cn/sql-reference/sql-functions/string-functions/concat.md +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/concat.md @@ -1,13 +1,13 @@ # concat -## Description - -将多个字符串连接起来, 如果参数中任意一个值是NULL,那么返回的结果就是NULL - ## Syntax `VARCHAR concat(VARCHAR,...)` +## Description + +将多个字符串连接起来, 如果参数中任意一个值是 NULL,那么返回的结果就是 NULL + ## Examples ``` diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/concat_ws.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/concat_ws.md index a20b4d3c9e..d72b7fd7e6 100644 --- a/docs/documentation/cn/sql-reference/sql-functions/string-functions/concat_ws.md +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/concat_ws.md @@ -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 diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/find_in_set.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/find_in_set.md new file mode 100644 index 0000000000..121a6672e2 --- /dev/null +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/find_in_set.md @@ -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 | ++---------------------------+ +``` diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/group_concat.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/group_concat.md new file mode 100644 index 0000000000..f1a3151516 --- /dev/null +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/group_concat.md @@ -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 | ++----------------------------+ +``` diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/instr.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/instr.md new file mode 100644 index 0000000000..58276bf4c4 --- /dev/null +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/instr.md @@ -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 | ++-------------------+ +``` diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/lcase.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/lcase.md new file mode 100644 index 0000000000..be8464ba14 --- /dev/null +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/lcase.md @@ -0,0 +1,10 @@ +# lcase + +## Syntax + +`INT lcase(VARCHAR str)` + +## Description + +与`lower`一致 + diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/length.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/length.md new file mode 100644 index 0000000000..03b3ce42bb --- /dev/null +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/length.md @@ -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 | ++------------------+ +``` diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/locate.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/locate.md new file mode 100644 index 0000000000..e6a7704381 --- /dev/null +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/locate.md @@ -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 | ++-------------------------------+ +``` diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/lower.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/lower.md new file mode 100644 index 0000000000..776d559c19 --- /dev/null +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/lower.md @@ -0,0 +1,20 @@ +# lower + +## Syntax + +`INT lower(VARCHAR str)` + +## Description + +将参数中所有的字符串都转换成小写 + +## Examples + +``` +mysql> SELECT lower("AbC123"); ++-----------------+ +| lower('AbC123') | ++-----------------+ +| abc123 | ++-----------------+ +``` diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/lpad.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/lpad.md new file mode 100644 index 0000000000..8ba1176ea5 --- /dev/null +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/lpad.md @@ -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 | ++---------------------+ +``` diff --git a/docs/documentation/cn/sql-reference/sql-functions/string-functions/ltrim.md b/docs/documentation/cn/sql-reference/sql-functions/string-functions/ltrim.md new file mode 100644 index 0000000000..4a265d0868 --- /dev/null +++ b/docs/documentation/cn/sql-reference/sql-functions/string-functions/ltrim.md @@ -0,0 +1,20 @@ +# ltrim + +## Syntax + +`VARCHAR ltrim(VARCHAR str)` + +## Description + +将参数 str 中从开始部分连续出现的空格去掉 + +## Examples + +``` +mysql> SELECT ltrim(' ab d'); ++------------------+ +| ltrim(' ab d') | ++------------------+ +| ab d | ++------------------+ +```