bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL References
SQL•SQL References

MySQL INSTR() Function

Concept visual

MySQL INSTR() Function

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

Example

Search for "3" in string "W3Schools.com", and return position:

SELECT INSTR("W3Schools.com", "3") AS MatchPosition;

Definition and Usage

The INSTR() function returns the position of the first occurrence of a string in another string.

Formula

This function performs a case - insensitive search.

Syntax

Instr(

string1, string2 )

Parameter Values

Parameter

Description string1

Required. The string that will be searched string2 Required. The string to search for in string1. If string2 is not found, this function returns 0

Technical Details

Works in:

From MySQL 4.0

More Examples

Example

Search for "COM" in string "W3Schools.com", and return position:

SELECT INSTR("W3Schools.com", "COM") AS MatchPosition;

Example

Search for "a" in CustomerName column, and return position:

SELECT INSTR(CustomerName, "a")
FROM Customers;

Previous

❮ MySQL Functions

Next

Previous

MySQL INSERT() Function

Next

MySQL LCASE() Function