Remove duplicate words from a address using oracle pl/sql:
There are two types of addresses will be there, below is the example,
1. \'3 Mayers Court 3 Mayers
If these are the only cases that may appear in your data you could use query below. You can put this logic into function, but query is faster, simpler.
Nothing fancy here, I'm just dividing string into half and comparing with source. Works for given examples, obviously there may be cases where you need more logic. For instance if you have consecutive spaces in string you have to get rid of them at first.
demo
select address,
case when address like sub||'%'
then substr(address, 1, length(address) - length(sub))
else address
end trimmed
from (select address, trim(substr(address, instr(address, ' ', 1, sn/2 + 1))) sub
from (select address, regexp_count(address, ' ') sn from t))
Result:
ADDRESS TRIMMED
----------------------------- -----------------------------
3 Mayers Court 3 Mayers Court 3 Mayers Court
905 Mayers Street 905 Mayers Street
Manor House Manor Manor House
1 Briar Cottages 1 Briar 1 Briar Cottages