Skip to content

Commit

Permalink
Add examples for FIELD() and FIND_IN_SET() (#16985) (#16990)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Apr 3, 2024
1 parent ac0628d commit e57c798
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions functions-and-operators/string-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,36 @@ SELECT CONCAT_WS(',', 'TiDB Server', 'TiKV', 'PD');

返回参数在后续参数中出现的第一个位置

在以下示例中,`FIELD()` 的第一个参数是 `needle`,它与后续列表中的第二个参数匹配,因此函数返回 `2`

```sql
SELECT FIELD('needle', 'A', 'needle', 'in', 'a', 'haystack');
+-------------------------------------------------------+
| FIELD('needle', 'A', 'needle', 'in', 'a', 'haystack') |
+-------------------------------------------------------+
| 2 |
+-------------------------------------------------------+
1 row in set (0.00 sec)
```

### [`FIND_IN_SET()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_find-in-set)

返回第一个参数在第二个参数中出现的位置

该函数通常与 [`SET`](/data-type-string.md#set-类型) 数据类型一起使用。

在以下示例中,`Go` 是集合 `COBOL,BASIC,Rust,Go,Java,Fortran` 中的第四个元素,因此函数返回 `4`

```sql
SELECT FIND_IN_SET('Go', 'COBOL,BASIC,Rust,Go,Java,Fortran');
+-------------------------------------------------------+
| FIND_IN_SET('Go', 'COBOL,BASIC,Rust,Go,Java,Fortran') |
+-------------------------------------------------------+
| 4 |
+-------------------------------------------------------+
1 row in set (0.00 sec)
```

### [`FORMAT()`](https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_format)

`FORMAT(X,D[,locale])` 函数用于将数字 `X` 格式化为类似于 `“#,###,###.##”` 的格式,四舍五入保留 `D` 位小数,并将结果作为字符串返回。
Expand Down

0 comments on commit e57c798

Please sign in to comment.