LOCATE vs INSTR

Viewed 11616
    SELECT INSTR('1234','2')  #returns 2
    SELECT LOCATE('2','1234') #returns 2

Besides the argument numbering are there any significant differences to be aware of before choosing either of the functions?

2 Answers

The INSTR() function starts the search from the first character.

The LOCATE() function has a third parameter which allows you to change the starting position.

-- returns 4
SELECT INSTR("Alibaba", "ba")

-- returns 4 because the third parameter was not specified
SELECT LOCATE("ba", "Alibaba")

-- returns 6
SELECT LOCATE("ba", "Alibaba", 5)
Related