2 ck zoubo CK_zoubo 于 2017.01.07 19:50 提问

游标提取数据,读取根据条件修改员工的年奖金。通过后的update该怎么写?大神...帮帮忙..

declare
v_empno employee.empno%type;
v_start number;
v_getdate number;
v_year number;
cursor emp_commcus IS
select empno,to_number(to_char(hiredate,'yyyy')) from employee;
begin
open emp_commcus;
loop
fetch emp_commcus into v_empno,v_start;
select to_number(to_char(sysdate,'yyyy')) into v_getdate from dual;
v_year:=v_getdate-v_start;
if v_getdate>=6 then
update employee set comm=comm+2000 where empno=v_empno; --该怎么写
else
update employee set comm=comm+1500 where empno=v_empno; -- 怎么写
end if;
end loop;
close emp_commcus;
end;

2个回答

CK_zoubo
CK_zoubo   2017.01.08 19:32
已采纳

declare
v_start number;
v_getdate number;
v_year number;
cursor c IS
select empno,to_number(to_char(hiredate,'yyyy')) from employee for update;
v_row c%rowtype;
v_empno employee.empno%type;
begin
open c;
for v_row in c loop
fetch c into v_empno,v_start;
select to_number(to_char(sysdate,'yyyy')) into v_getdate from dual;
v_year:=v_getdate-v_start;
if v_getdate>=6 then
update employee set comm=comm+2000 where current of c;

dbms_output.put_line(v_empno);
else
update employee set comm=comm+2000 where current of c;

dbms_output.put_line(v_empno);
end if;
end loop;
close c;
end;

我个人又改善了一次然后跟我报错说“已打开了游标”

qq_29566841
qq_29566841   2017.01.08 14:57

你上边这个写法报了什么错误呢?

CK_zoubo
CK_zoubo 看下面我的评论大神,还是报错说已打开游标
11 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片