> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# field

> 返回值在一组值中的索引位置。

返回某个值在一组值中的索引（位置）。

此函数从 v3.5 开始支持。

## 语法

```sql theme={null}
INT field(VARCHAR val, VARCHAR val1, val2, ...);
```

* `val`：要在列表中搜索的值。
* `val1`，`val2`，...：列表中的值。

## 使用说明

* 如果在值列表中未找到指定值，该函数将返回 `0`。如果指定值为 NULL，该函数将返回 `0`。
* 如果函数的所有参数都是字符串，则所有参数将作为字符串进行比较。如果所有参数都是数字，则作为数字进行比较。否则，参数将作为 DOUBLE 进行比较。

## 示例

```sql theme={null}
MYSQL > select field('a', 'b', 'a', 'd');
+---------------------------+
| field('a', 'b', 'a', 'd') |
+---------------------------+
|                         2 |
+---------------------------+
```

## 关键字

FIELD


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.