Thanks!
Peter Tran, April 15, 2009 - 3:18 pm UTC
You're absolutely right. I didn't think about the issue of having the data I want replaced being embedded inside an existing word like your example #3 below.
I love Oracle's RegEx feature!!!
Why replace statement replace all rows
Ajay, January 06, 2014 - 12:51 pm UTC
Hi Tom,
I have a quick question. I have a table with two columns. were I want to update only one row using replace function.
But when I use to to update, it updates all rows in table.
demonstration:
desc test
Name Null? Type
------- -------- --------------
X VARCHAR2(10)
Y VARCHAR2(10)
SQL> select * from test;
X Y
---------- ----------
ajay singh
ajay singh
ajay singh
ajay singh
ajay singh
ajay singh
ajay singh
ajay singh
ajay singh
ajay singh
ajay singh
raj singh
SQL> update test set X=replace(X,'raj','ajay');
16 rows updated.
SQL> rollback;
Rollback complete.
SQL> update test set X=replace(X,'RAJ','ajay') where X='raj';
1 row updated.
commit;
Questions:
1. Do replace function replaces all rows in table, or it find the pattern in and replace it.
2. Why we need to specifically write where clause to make replace function understand , which row we need to update.