Multiple update conditions in single query
Assume we have a table called Suppliers(Supp_Id varchar2(10), Supp_Name varchar2(50)) having the following data.
Supp_Id |
Supp_Name |
supp1 |
TCS |
supp2 |
Wipro |
Prob: I want to modify "TCS" with "Tata Consultancy Services" and "Wipro" with "Wipro Technologies" in a single query.
Sol: UPDATE Suppliers SET Supp_Name=
CASE
WHEN supp_name='TCS' then 'TataConsultancyServices'
WHEN supp_name='Wipro' then 'Wipro Technologies'
END
WHERE supp_name IN('TCS','Wipro');
Note:IN clause is optional to escape the query from being updated all the records.