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
Syntax
instr(X, Y)
Parameters
| Parameter | Description |
|---|---|
X |
The string to search in. |
Y |
The string to find. |
Return value
An integer (0 when not found), or NULL.
Examples
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
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
| Version | Change |
|---|---|
| SQLite 3.7.15 | Added |
In other languages
POSITION()· PostgreSQL
Related
SUBSTR()· Return part of a string starting at a 1-based position, with an optional length. Negative starts count from the end.LIKE· Match a string against a pattern with % (any run of characters) and _ (one character). Case-insensitive for ASCII.- SQL String Functions · tutorial