Friday, July 18, 2008

Search and Replace in Oracle

Suppose you want to update String value of a column based on search and replace, you can use Replace function of Oracle. It takes 3 parameters as follows.
1. Column name you are interested in to find and replace values of
2. Search String
3. Replacement String

for example, you can update the values of all names if they contain 'Ram' in themselves by 'Shyam'.

update user_account set user_name = replace(user_name, 'Ram','Shyam');
This will first search all user_names for 'Ram' and then updates them with String 'Shyam';

Sphere: Related Content

4 comments:

betheb said...
This comment has been removed by the author.
betheb said...

the above syntax doesn't work. this is the correct syntax:

UPDATE table_name
SET name = REPLACE(name, 'oldname', 'newname')
WHERE name like '%oldname%';

Stephan Schielke said...

Thx!
Works finde and saved me some time :-)

BLOG TEST said...

Thanks a lot it worked for me awesome !!!