I have an ordered list of words separated by single space. I did like to return only distinct words from the list. For e.g.
1) "a aa aa b c" --> "a aa b c"
2) "a b c c c" --> "a b c"
I have
with
src as (
select 'a aa aa b c' as str from dual union all
select 'a b c c c' as str from dual
)
select regexp_replace(str, '([^ ]+)( \1)+','\1') regexp1
, regexp_replace(str, '([^ ]+ )\1+','\1') regexp2
, regexp_replace(rtrim(str)||' ', '([^ ]+ )(\1)+','\1') regexp3
from src
/
column regexp1 gets 2) right not 1)
column regexp2 gets 1) right not 2)
column regexp3 gets both right but, can this be done without appending an extra space