Introduction
LOCATE and INSTR help find where a smaller piece of text appears inside a bigger text. This is useful to check if a word or letter is inside a sentence and where it starts.
LOCATE(substring, string[, start_position]) INSTR(string, substring)
SELECT LOCATE('cat', 'concatenate');
SELECT LOCATE('cat', 'concatenate', 5);
SELECT INSTR('concatenate', 'cat');
SELECT INSTR('hello world', 'z');
SELECT LOCATE('day', 'Today is a sunny day') AS locate_result, INSTR('Today is a sunny day', 'day') AS instr_result;
LOCATE('cat', 'concatenate') return?SELECT INSTR('hello world', 'o');SELECT LOCATE('test', 'testing', 0);Pass the test and this pattern moves unknown