Explain INSTR Function in SQL?

This function in MySQL is used to return the location of the first occurrence of a substring within a given string.

Syntax :

INSTR(string_1, string_2)

Parameters :

This function accepts 2 parameters.

  • string_1 – The string where searching takes place.
  • string_2 – The string/sub-string which will be searched in string_1.

Returns :

It returns the position of the first occurrence of a substring within a given string.

Note –

  • The function will return 0 if string_2 is not found in string_1.
  • INSTR() function only performs case-insensitive searches.

Example: Finding the position of a sub-string.

SELECT INSTR("Python is a powerful Language", "powerful")
AS Found;

Output :

Found

13