Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating database records in a loop?

Tags:

sql

plsql

declare
begin
  for i in (select * from emp)
  loop
    if i.sal=1300 then
      update emp
      set sal=13000;
    end if;
  end loop;
end;

This code is updating all the records with salary 13000.
Instead i want to update records having salary 1300 to the value 13000.
Can you tell where I made a mistake?
I am accesing records using implicit cursor..
for every record i am checking the sal value of that record..
if salary value in a particular record is 1500 i want to update it to 15000..

like image 392
musicking123 Avatar asked Nov 27 '22 21:11

musicking123


1 Answers

delete that code and just use:

update emp set sal = 13000 where sal = 1300
like image 179
Sergio Avatar answered Dec 10 '22 02:12

Sergio