我做案列2的时候,统计后的结果为什么有10条。数据准确但是有重复。后来在游标的查询语句中加了去重才好了。为什么教程不用加?
2022-05-27
loop
fetch sals into csal,cempno;
select sum(sal) into saltotal from emp;
exit when sals%notfound or saltotal*1.1>=50000;
saltotal:=saltotal*1.1;
ccount:=ccount+1;
update emp set sal=sal*1.1 where empno=cempno;
end loop;
close sals;
fetch sals into csal,cempno;
select sum(sal) into saltotal from emp;
exit when sals%notfound or saltotal*1.1>=50000;
saltotal:=saltotal*1.1;
ccount:=ccount+1;
update emp set sal=sal*1.1 where empno=cempno;
end loop;
close sals;
2021-02-07
loop
fetch cs into pempno,psal;
exit when salTotal>50000 or cs%notfound;
if (salTotal + psal*0.1)>50000 then exit;
else
update emp set sal =sal *1.1 where empno=pempno;
countEmp :=countEmp+1;
salTotal :=salTotal + psal*0.1;
end if;
end loop;
fetch cs into pempno,psal;
exit when salTotal>50000 or cs%notfound;
if (salTotal + psal*0.1)>50000 then exit;
else
update emp set sal =sal *1.1 where empno=pempno;
countEmp :=countEmp+1;
salTotal :=salTotal + psal*0.1;
end if;
end loop;
2020-05-18