I would need to reverse the word positions in a sentence or String.
For example : \"Hello World! I Love StackOverflow\", to be displayed as \"StackOverflow
Here you go:
WITH sel_string AS
(SELECT 'Hello World! I Love StackOverflow' AS fullstring FROM DUAL)
SELECT SUBSTR(fullstring, beg + 1, end_p - beg - 1) AS token
FROM (SELECT beg, LEAD(beg) OVER (ORDER BY beg) AS end_p, fullstring
FROM (SELECT beg, fullstring
FROM (SELECT LEVEL beg, fullstring
FROM sel_string
CONNECT BY LEVEL <= LENGTH(fullstring))
WHERE INSTR(' ', SUBSTR(fullstring, beg, 1)) > 0
UNION ALL
SELECT 0, fullstring FROM sel_string
UNION ALL
SELECT LENGTH(fullstring) + 1, fullstring FROM sel_string))
WHERE end_p IS NOT NULL AND
end_p > beg + 1
ORDER BY ROWNUM DESC;
All in one SQL query. I wish I could claim credit for this query but I can't - found it years ago on the net and have used it ever since.
Share and enjoy.