您的位置:首页 > 其它

利用游标update数据

2015-06-26 14:37 330 查看
更新或修改数据的语法:

update / delete .... where current of cursor_name;

前提是游标要先定义for update,否则不能修改数据库中的数据:

例:

修改员工的工资,如果员工的部门号为10,则工资提高1000;如果部门号为20,则工资提高1500;如果部门号为30,则工资提高2000;否则工资提高2500。

declare
cursor c_emp is
select e.deptno, e.salary from employees e for update ;
v_salary in number;

begin
for c_emp_rec in c_emp loop
case c_emp_rec.deptno
when 10 v_salary :=1000;
when 20 v_salary :=1500;
when 30 v_salary :=2000;
else v_salary :=2500;
end case;

update employees e set e.salary = nvl(e.salary,0)+v_salary where current of c_emp;

end loop;

commit;

end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: