利用游标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;
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;
相关文章推荐
- Lucene提供的条件判断查询
- 让盘古分词支持最新的Lucene.Net 3.0.3
- 《算法:C语言实现》阅读笔记
- 二维符号库的制作总结
- windows 10系统怎么设置图形密码?
- 个人笔记小记,about network of android
- Java基础面试题
- 黑马程序员_0基础黑马路
- android 开发赚钱
- 什么是 WSGI -- Python 中的 “CGI” 接口简介
- 运行及总结
- ARC的实现机制
- msvc2010生成的指令序列有问题,可能跟pgo有关
- Python Django开发 1
- UFLDL Exercise:Self-Taught Learning
- Deep Learning(深度学习)学习笔记整理系列之(六)
- 关于cpu和numa
- 学习日记-C语言结构体(struct)
- Java中的泛型使用详细介绍
- Java collection