Skip to content

Commit

Permalink
add new doc of locate(#874) (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangj1211 authored Dec 16, 2023
1 parent a35f802 commit 06a77b6
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
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

0 comments on commit 06a77b6

Please sign in to comment.