Updating database records in a loop?

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 updates all records with a salary of 13000.
Instead, I want to update records with a salary of 1300 to a value of 13000.
Can you tell me where I made a mistake?
I use entries using an implicit cursor.
for each record, I check the sal value of this record. If the salary value in a particular record is 1500, I want to update it to 15000.

+3
source share
4 answers

, , . , ; , , .

, , where, , , . , ( ), rowid:

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

- "update... where current of cursorname".

+9

:

update emp set sal = 13000 where sal = 1300
+25

.

, , , 1300, SQL:

update emp 
set sal=13000;

.

+5

13000. , 1300, 13000.

sal . 1500, 15 000.

, ?

1500 , :

UPDATE emp
SET sal = 15000
WHERE sal = 1500;

, :

UPDATE emp
SET sal = sal * 10;
+5

Source: https://habr.com/ru/post/1703344/


All Articles