MySQL INSTR() Function
Example
Search for "3" in string "W3Schools.com", and return position:
SELECT INSTR("W3Schools.com", "3") AS MatchPosition;
Try it Yourself »
Definition and Usage
The INSTR() function returns the position of the first occurrence of a string in another string.
Syntax
INSTR(string, substring)
Parameter Values
Parameter | Description |
---|---|
string | Required. The string that will be searched |
substring | Required. The substring to search for in string |
Note
- INSTR() performs a case-insensitive search
- The first position in string is 1
- If substring is not found within string, the INSTR() function will return 0
Technical Details
Works in: | MySQL 5.7, MySQL 5.6, MySQL 5.5, MySQL 5.1, MySQL 5.0, MySQL 4.1, MySQL 4.0, MySQL 3.23 |
---|
More Examples
Example
Search for "COM" in string "W3Schools.com", and return position:
SELECT INSTR("W3Schools.com", "COM") AS MatchPosition;
Try it Yourself »
Example
Search for "a" in CustomerName column, and return position:
SELECT INSTR(CustomerName, "a")
FROM Customers;
Try it Yourself »