存储过程 loop


cursor c_emp is select job,empno,ename from emp for update;
c_manager constant number :=0.30;
c_salesman constant number :=0.4;
v_job varchar(100);
v_empno varchar(100);
v_ename varchar(100);


begin
open c_emp;
loop
fetch c_emp
into v_job, v_empno,v_ename;
exit when c_emp%notfound;
if v_job='MANAGER'
then update emp set sal=sal*(1+c_manager)
where current of c_emp;

elsif v_job='SALESMAN'
then update emp set sal=sal*(1+c_salesman)
where current of c_emp;
end if;
dbms_output.put_line('为员工'||v_empno||'成功加薪');
end loop;
close c_emp;
exception
when no_data_found
then
dbms_output.put_line('没有找到数据');

posted @ 2018-10-29 11:59  淡蓝浅紫  阅读(652)  评论(0编辑  收藏  举报