pl sql 问题:给工资低于1200 的员工增加工资50

2025-03-29 19:03:59
推荐回答(2个)
回答1:

declare
rec_sal emp.sal%type;
rec_empno emp.empno%type;--加了一个变量,员工号
cursor c1 is
select empno,sal from emp;--取游标时把员工号也取出
 begin
 open c1;
  loop
  fetch c1 into rec_empno,rec_sal;
  if rec_sal <1200 then
   update emp set sal=rec_sal+50 where empno=rec_empno;--看出和你不一样的地方了吗?这里加了一个where条件,游标循环时只修改当前这条数据,而你是把所有的都update了
  end if;
  exit when c1%notfound;
  end loop;
  close c1;
  end;

 

 

你那个1000不是哪来的,是游标循环时取出的最后一条小于1200的数据

回答2:

没加任何条件来更新