Find the position of “3” within the string “W3Schools.com” and return its location.
SELECT INSTR(“W3Schools.com”, “3”) AS MatchPosition; |
The INSTR() function identifies the position of the initial appearance of one string within another, conducting a search that isn’t case-sensitive.
INSTR(string1, string2) |
Parameter |
Description |
string1 |
Mandatory: The string to be searched. |
string2 |
Necessary: The string to look for within string1. If string2 isn’t found, this function returns 0. |
Works in: | From MySQL 4.0 |
Find the position of “COM” within the string “W3Schools.com” and provide its location.
SELECT INSTR(“W3Schools.com”, “COM”) AS MatchPosition; |
Find the position of the character “a” within the CustomerName column and return its location.
SELECT INSTR(CustomerName, “a”) FROM Customers; |