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

# LOCATE

> Returns a substring position.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

**Aliases:** [`strpos`](/query/sql/functions/string/strpos), [`charindex`](/query/sql/functions/string/charindex)

NULL string/search, or a supplied NULL start/occurrence operand, returns NULL. Omitted start and occurrence default to one.

## Syntax

### Scalar

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
locate(search, value[, start])
```

### Strpos form (scalar)

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
strpos(value, search[, start])
```

* Use STRING search and value operands and an INTEGER start of at least one.

### Charindex form (scalar)

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
charindex(search, value[, start])
```

* Use STRING search and value operands and an INTEGER start of at least one.

## Arguments

### Scalar, charindex form

| Name | Type | Required | Description |
| - | - | - | - |
| search | STRING | Yes | Needle. |
| value | STRING | Yes | Haystack. |
| start | INTEGER | No | Positive starting character position. Positive values (at least 1) for the supported forward-search contract. Default: 1. |

### Strpos form

| Name | Type | Required | Description |
| - | - | - | - |
| value | STRING | Yes | Haystack. |
| search | STRING | Yes | Needle. |
| start | INTEGER | No | Positive starting character position. Positive values (at least 1) for the supported forward-search contract. Default: 1. |

## Returns

* Type: BIGINT; query tools may report INTEGER
* Possible values: One-based position or zero when absent.
* NULL behavior: NULL string/search, or a supplied NULL start/occurrence operand, returns NULL. Omitted start and occurrence default to one.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Supports window usage | No |
| Exact result | Yes |

## Usage notes

* INSTR uses haystack, needle; LOCATE uses needle, haystack.
* STRPOS takes the text to search first, then the substring. CHARINDEX and LOCATE take the substring first, then the text to search.

## Examples

### Typical behavior

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT locate('ll', 'Hello') AS "value";
```

| value |
| - |
| 3 |

### Alias calling form: STRPOS

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT strpos('Hello', 'll') AS "value";
```

| value |
| - |
| 3 |

### Alias calling form: CHARINDEX

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT charindex('ll', 'Hello') AS "value";
```

| value |
| - |
| 3 |

## Limitations

* The position is returned as BIGINT, even when query tools report INTEGER.
* Use start and occurrence values of at least 1. Zero or negative values can fail or give unexpected results. For non-ASCII text, a start position beyond the string’s length can restart the search at the beginning.


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