We can find the index of the first occurrence of a given substring in MySQL using the INSTR()
function as follows.
SELECT instr('Have_a_good_day', '_') AS index_position
It would display 5
, the first occurrence of the specified substring which is in this case an underscore _
.
I need to obtain the last occurrence of a given character (or a substring) something like the Java lastIndexOf(String str)
method of the String class but I can't find any built-in function in MySQL.
Is there any built-in functionality to achieve this in MySQL?