Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new doc of locate(matrixorigin#874) #882

Merged
merged 1 commit into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
73 changes: 73 additions & 0 deletions docs/MatrixOne/Reference/Functions-and-Operators/String/locate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# **LOCATE()**

## **函数说明**

`LOCATE()` 函数是用于在字符串中查找子字符串所在位置的函数。它返回子字符串在字符串中的位置,如果未找到,则返回 0。

由于 `LOCATE()` 函数返回的是一个整数值,所以它可以嵌套在其他函数里面使用,比如可以用 substring 函数截取字符串。

关于大小写,`LOCATE()` 函数不区分大小写。

## **函数语法**

```
> LOCATE(subtr,str,pos)
```

## **参数释义**

| 参数 | 说明 |
| ---- | ---- |
| substr | 必要参数。`substring` 是你正在查找的字符串。|
| str | 必要参数。`string` 是要在其中搜索的字符串。|
| pos | 非必要参数。`position` 是表示开始查询的位置。|

## **示例**

- 示例 1

```sql
mysql> SELECT LOCATE('bar', 'footbarbar');
+-------------------------+
| locate(bar, footbarbar) |
+-------------------------+
| 5 |
+-------------------------+
1 row in set (0.00 sec)
```

- 示例 2

```sql
mysql>SELECT LOCATE('bar', 'footbarbar',6);
+----------------------------+
| locate(bar, footbarbar, 6) |
+----------------------------+
| 8 |
+----------------------------+
1 row in set (0.00 sec)
```

- 示例 3

```sql
mysql>SELECT SUBSTRING('hello world',LOCATE('o','hello world'),5);
+---------------------------------------------------+
| substring(hello world, locate(o, hello world), 5) |
+---------------------------------------------------+
| o wor |
+---------------------------------------------------+
1 row in set (0.00 sec)
```

- 示例 4

```sql
mysql>select locate('a','ABC');
+----------------+
| locate(a, ABC) |
+----------------+
| 1 |
+----------------+
1 row in set (0.00 sec)
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ nav:
- INSTR(): MatrixOne/Reference/Functions-and-Operators/String/instr.md
- LEFT(): MatrixOne/Reference/Functions-and-Operators/String/left.md
- LENGTH(): MatrixOne/Reference/Functions-and-Operators/String/length.md
- LOCATE(): MatrixOne/Reference/Functions-and-Operators/String/locate.md
- LOWER(): MatrixOne/Reference/Functions-and-Operators/String/lower.md
- LPAD(): MatrixOne/Reference/Functions-and-Operators/String/lpad.md
- LTRIM(): MatrixOne/Reference/Functions-and-Operators/String/ltrim.md
Expand Down