i want substring of string beginning last occurence of search string.
example string: "abcd corp org work with. abcd corp incorporated"
search string: "corp"
expected output: "abcd corp org work with. abcd "
ie. string uptil last occurrence of search string.could suggest best way it?
here way, not efficient way:
mysql> set @a = "abcd corp org work with. abcd corp incorporated"; query ok, 0 rows affected (0.00 sec) mysql> select substring(@a, 1, length(@a) - length('corp') - instr(reverse(@a), reverse('corp')) + 1); +-----------------------------------------------------------------------------------------+ | substring(@a, 1, length(@a) - length('corp') - instr(reverse(@a), reverse('corp')) + 1) | +-----------------------------------------------------------------------------------------+ | abcd corp org work with. abcd corp in | +-----------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
Comments
Post a Comment