Problem using substr() function in MySql
Posted on 2014-03-20
I need to extract a string A from string B where B is stored in MySQL table.
This is string B:
And this is A:
The delimiter in my case is '#' and I need to remove it along with the following characters '/element[productImage]'.
I tried different functions like SUBSTR(str, pos, len), POSITION(substr IN str), and REVERSE(str) but cannot solve the problem.
Note that index of the last occurrence of '#' is unknown. And I can not find a way to locate the last index of the '#' character (like lastIndexOf() function in JAVA).
I believe that there is a way to do it by reversing the whole string first, cutting the unnecessary part then reversing again to get the desired result.
Can any one help please