I need to update a column based on the conditions i used below, the update query i used is updating null values as well. How can i stop that and retain the old values when no match was found for the case.
create table sample (name varchar2(10),eno number(10),salary number(10));
insert into sample (name,eno,salary) values ('emp1',1,100);
insert into sample (name,eno,salary) values ('emp2',2,200);
insert into sample (name,eno,salary) values ('emp3',3,300);
select * from sample;
update sample
set salary =
case when salary = 100 then 10000 else
case when salary = 150 then 15000 else
case when salary = 200 then 20000 end end end
where name is not null;
Actual o/p:
emp1 1 10000
emp2 2 20000
emp3 3
Required o/p:
emp1 1 10000
emp2 2 20000
emp3 3 300