Skip to content
Advertisement

Standardizing addresses using regexp_replace in oracle sql

I really appreciate all of you for your help.

We are in the process of standardizing the addresses of our customers.

I have a main customer table which contains the customers data, the address field to be standardized.

I have a mapping table that contains mapping for from_str to to_str values.

I need to get the to_str that is correspond to the from_str into the address data.

If the length of the address is more than 35 characters after standardizing, then from previous space(‘ ‘) from right side to end of the string, is created as a seperate field address2

Could you please help with sql or pl/sql? Using Oracle 12c database.

The code I wrote below is not working for all from_str values…only working for first 2 rows.

Any help is appreciated.

code so far:

Expected Output:

if length of the address is more than 35 characters then the expected output is:

Advertisement

Answer

That’s an… interesting way to apply multiple replace operations. So – you have 2 issues, as you mentioned. For the first one, the recursive part of your CTE is doing regexp_replace() on addr instead of test_addr (the modified output of the previous recursive step). So only the last rule in the list is ever applied.

For the “over-35-characters” issue, I would suggest using substr/instr – while awkward to read, they’re usually fast.

There’s probably a more graceful way to do that part, it’s just the first thing that came to mind.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement