INSTR function
Returns the position of the first occurrence of a substring within a string.
Syntax
INSTR(string, substring)
Arguments
string: The string to search within.substring: The substring to search for.
Returns
A BIGINT representing the position of the substring (1-based index). Returns 0 if the substring is not found.
Examples
-- Example 1: Find first occurrence
> SELECT INSTR('abc', 'b');
2
-- Example 2: Find overlapping substring
> SELECT INSTR('abbba', 'bb');
2
-- Example 3: Substring not found
> SELECT INSTR('Hello World', 'x');
0
-- Example 4: Case-sensitive search
> SELECT INSTR('Hello World', 'h');
0
> SELECT INSTR('Hello World', 'H');
1
-- Example 7: Unsupported syntax (will error)
> SELECT INSTR('abbba', 'bb', 2, 2);
ERROR
> SELECT INSTR('abbba', 'bb', -2);
ERROR
See Also
STRPOS function - Similar function for finding substring position
SUBSTRING function - Extract part of a string