Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Update query using case updating null values

Oracle_WalkerJun 5 2012 — edited Jun 6 2012
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
This post has been answered by Frank Kulash on Jun 5 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 4 2012
Added on Jun 5 2012
7 comments
2,709 views