I need this to be done in Oracle SQL (10gR2). But, I think, I would say that any good, efficient algorithm is fine.
If you specified a string (or a sentence containing one or more words, English), how do you find the last word of the sentence?
Here is what I tried in SQL. But I would like to see an effective way to do this.
select reverse(substr(reverse(&p_word_in) , 0 , instr(reverse(&p_word_in), ' ') ) ) from dual;
The idea was to swap the string, find the first counter space, get the substring and change the string. Is it effective enough? Is regex available? I am on Oracle 10g R2. But I do not mind any attempts in another programming language, but I will not write a PL / SQL function if necessary.
Update:
Jeffrey Kemp gave a wonderful answer. It works great.
Answer
SELECT SUBSTR(&sentence, INSTR(&sentence,' ',-1) + 1) FROM dual
source share