Character Replace in Oracle SQL

In my sql query I am pulling all the email address from my company; example john.smith@abc.com
We are changing our domain to john.smith@hospital.org

Want to know if there is a way for me to search for the string @abc.com and replace it with @hospital.org in my query?
metalteckAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

johnsoneSenior Oracle DBACommented:
The REPLACE function should do what you need.
0
slightwv (䄆 Netminder) Commented:
First:  You should ask Oracle questions in the Oracle Database Topic Area.  Some of us don't monitor other areas and can easily miss questions.  I've changed the Topic Areas for you.

You really don't provide enough information.

Do you have stored procedures/functions/packages that have that email address in them that you want to replace?
Do you have a folder in some OS that has a lot of scripts that you wish to replace?
What?

If in Oracle code, you can use a query against user_source to find the code that has the domain:
select name, type from user_source where lower(text) like '%@abc.com%';

Then you can use dbms_metadata.get_ddl to extract the actual DDL, to a simple replace with your favorite editor and re-execute the DDL.
0
Doug WaltonDatabase AdministratorCommented:
Just to add to what was said already, it would end up looking something like this:

select <email column>, REPLACE(<email column>,'@abc.com','@hospital.org') from <table name> where <email column> like '%@abc.com';
update <table name> set <email column> = REPLACE(<email column>,'@abc.com','@hospital.org') where <email column> like '%@abc.com';

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
slightwv (䄆 Netminder) Commented:
>>it would end up looking something like this:

The assumption is they are using a single email address column in a table or series of tables.  The problem is more involved if there is the possibility of more than one column in a table that might contain the email address.

It also assumes @abc.com is the entire end of the field.  If you are updating a column where the email address can exist in blocks of text, the above statements won't work.  You will need to double-ended wildcard in my example.
1
slightwv (䄆 Netminder) Commented:
I used it in my example but thought I should make sure I mention it:  The REPLACE commands mentioned don't account for the case of the email addresses.  You might need to use the UPPER or LOWER functions to make sure you find everything and again with the replace to make sure you replace everything.

So, Doug's update statement will be:
update <table name> set <email column> = REPLACE(lower(<email column>),'@abc.com','@hospital.org') where lower(<email column>) like '%@abc.com';

Open in new window

1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.