SQLite instr() Function

The SQLite instr() function finds the first occurrence of a given string within a given string, and returns a number (1-based) representing the position of the first occurrence if found, otherwise 0.

Syntax

Here is the syntax of the SQLite instr() function:

instr(str1, str2)

Parameters

str1

Required. The string to search for.

str2

Required. The string to be searched for.

Return value

The SQLite instr() function find the first occurrence of a given string str2 within a given string str1, and returns a number (1-based) representing the position of the first occurrence if found, otherwise 0.

Examples

To find the position of the string he within the string hello, use the following statement:

SELECT instr('hello', 'he');
instr('hello', 'he')
--------------------
1

To find the position of the string ll within the string hello, use the following statement:

SELECT instr('hello', 'll');
instr('hello', 'll')
--------------------
3

To find the position of the string abc within string hello, use the following statement:

SELECT instr('hello', 'abc');
instr('hello', 'abc')
---------------------
0