How can I replace multiple specified strings in Oracle?

In Oracle, we can use the REPLACE function to replace a specified string. However, to replace multiple specified strings, we can use the REGEXP_REPLACE function combined with regular expressions to achieve this. Here is an example:

Assuming we have a table named employees, which has a job_title column containing different job titles. We want to replace Engineer with Software Engineer, and Manager with Project Manager.

The following statements can be used to achieve:

UPDATE employees
SET job_title = REGEXP_REPLACE(job_title, 'Engineer', 'Software Engineer')
WHERE job_title LIKE '%Engineer%';

UPDATE employees
SET job_title = REGEXP_REPLACE(job_title, 'Manager', 'Project Manager')
WHERE job_title LIKE '%Manager%';

The statement above will replace all rows in the job_title column containing “Engineer” with “Software Engineer” and all rows containing “Manager” with “Project Manager”.

If you want to replace more specified strings, you can continue using the REGEXP_REPLACE function and add more UPDATE statements as needed.

bannerAds