STRPOS
All functions > STRING > STRPOS
Returns the position of a substring within a string, optionally finding the N-th occurrence.
Signatures
Returns: Position of the substring (1-indexed), or 0 if not found
STRPOS(string: VARCHAR, substring: VARCHAR, [occurrence: BIGINT]) → BIGINT sql
| Parameter | Type | Required | Description |
|---|---|---|---|
string | VARCHAR | Yes | String to search in |
substring | VARCHAR | Yes | Substring to find |
occurrence | BIGINT | No | Which occurrence to find (1 for first, 2 for second, etc.) - optional |
Notes
- Position is 1-indexed
- Returns 0 if substring not found
- If occurrence specified, finds N-th occurrence
- Case-sensitive search
- See also: POSITION
Examples
FeatureQL
SELECT
f1 := STRPOS('Hello World', 'World'), -- Basic search
f2 := STRPOS('Hello Hello World', 'Hello'), -- First occurrence
f3 := STRPOS('test', 'xyz') -- Not found
;Result
| f1 BIGINT | f2 BIGINT | f3 BIGINT |
|---|---|---|
| 7 | 1 | 0 |
On this page