---
title: instr function
description: Learn the syntax of the instr function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/instr
---

# `instr` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Returns the (1-based) index of the first occurrence of `substr` in `str`.

## Syntax

```
instr(str, substr)
```

## Arguments

* `str`: A `STRING` expression.
* `substr`: A `STRING` expression.

## Returns

A `BIGINT`.

If `substr` cannot be found the function returns 0.

## Examples

```sql
> SELECT instr('SparkSQL', 'SQL');
 6

> SELECT instr('SparkSQL', 'R');
 0

> SELECT instr('SparkSQL' COLLATE UTF8_LCASE, 'sql');
 6

> SELECT instr('SparkSQL' COLLATE UTF8_BINARY, 'sql');
 6
```

## Related functions

* [`locate` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/locate.md)
* [`position` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/position.md)
