CK_zoubo
只想你仍安好
2017-01-07 11:50
采纳率: 28.6%
浏览 843
已采纳

游标提取数据,读取根据条件修改员工的年奖金。通过后的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
    只想你仍安好 2017-01-08 11: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
    小瑾守护线程 2017-01-08 06:57

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

    点赞 评论

相关推荐