Function Reference

INSTR

PostgreSQL equivalent:

Returns the position of the first occurrence of a substring in a string.

MySQL 8.1
INSTR(str, substr)

Parameters

strVARCHAR
String to search in
substrVARCHAR
Substring to find

Return value

An integer position starting from 1; 0 if the substring is not found

Examples

Position of a substring

MySQL 8.1
SELECT INSTR('sql-academy', 'academy');
INSTR('sql-academy', 'academy')
5

Case-insensitive search

MySQL 8.1
SELECT INSTR('SQL Academy', 'academy');
INSTR('SQL Academy', 'academy')
5

Details

The arguments come in the reverse order compared to LOCATE: the string first, then the substring. The search is case-insensitive by default.

See also

Where to learn