SQLite 3 reference · String Functions

SQLite INSTR() Function

Return the 1-based position of the first occurrence of one string inside another, or 0 if it isn't found.

SQLite 3 Since 3.7.15

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

instr(X, Y)

Parameters

ParameterDescription
X The string to search in.
Y The string to find.

Return value

An integer (0 when not found), or NULL.

Examples

Find a characterTry it yourself
SELECT email, instr(email, '@') AS at_sign
FROM customers
WHERE email IS NOT NULL
LIMIT 3;

Output

email | at_sign
[email protected] | 4
[email protected] | 5
[email protected] | 8
Text after the @Try it yourself
SELECT email, substr(email, instr(email, '@') + 1) AS domain
FROM customers
WHERE email IS NOT NULL
LIMIT 3;

Output

email | domain
[email protected] | example.com
[email protected] | example.com
[email protected] | example.com

Version history

VersionChange
SQLite 3.7.15Added

In other languages

Was this page helpful?