user1251973 :
I have string
good morning what a lovely day today
I need to find the position of 'lovely'
. Query should return the result 5
.
GMB :
You can use find_in_set()
for this:
select find_in_set('lovely', replace('good morning what a lovely day today', ' ', ','))
Yields:
5
From the documentation:
FIND_IN_SET(str,strlist)
Returns a value in the range of
1
toN
if the stringstr
is in the string liststrlist
consisting ofN
substrings. A string list is a string composed of substrings separated by,
characters.
So basically the logic is to replace space characters with commas, and then use that function.