MySQL INSTR() Function

In MySQL, the INSTR() function returns the position of the first occurrence of a substring in a string. The INSTR() function is case-sensitive only if at least one argument is a binary string.

The INSTR() function is the same as POSITION() function and LOCATE() function with two parameters.

INSTR() Syntax

Here is the syntax of MySQL INSTR() function:

INSTR(str, substr)

Parameters

str
Required. The string to be searched.
substr
Required. A substring to search for in str.

Return value

Returns the position of the first occurrence of substring substr in string str.

The function will return 0 if str does not include substr.

The function will return NULL if any parameter is NULL.

INSTR() Examples

Here are some examples of MySQL INSTR() function.

SELECT
    INSTR('Hello World', 'He'),
    INSTR('Hello World', 'he'),
    INSTR('Hello World', 'wo'),
    INSTR('Hello World', 'go'),
    INSTR('Hello World', NULL),
    INSTR(NULL, 'go'),
    INSTR(NULL, NULL)\G
INSTR('Hello World', 'He'): 1
INSTR('Hello World', 'he'): 1
INSTR('Hello World', 'wo'): 7
INSTR('Hello World', 'go'): 0
INSTR('Hello World', NULL): NULL
         INSTR(NULL, 'go'): NULL
         INSTR(NULL, NULL): NULL