Character Replace in Oracle SQL

In my sql query I am pulling all the email address from my company; example
We are changing our domain to

Want to know if there is a way for me to search for the string and replace it with in my query?
Who is Participating?
Doug WaltonConnect With a Mentor Database AdministratorCommented:
Just to add to what was said already, it would end up looking something like this:

select <email column>, REPLACE(<email column>,'','') from <table name> where <email column> like '';
update <table name> set <email column> = REPLACE(<email column>,'','') where <email column> like '';

Open in new window

johnsoneSenior Oracle DBACommented:
The REPLACE function should do what you need.
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?

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 '';

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.
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 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.
slightwv (䄆 Netminder)Connect With a Mentor 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>),'','') where lower(<email column>) like '';

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.