--创建游标
cursor 游标名称 is sql语句
--打开游标
open 游标名称;
--遍历的数据存放到emprow记录型变量,fetch获取游标的数据
fetch cl into emprow;
--查询没有数据
%notfound
二.范例
三.语法二【带参数的游标格式】
declare
cursor cl2(eno emp.deptno%type)--对游标中存储的指定的参数进行数据类型设置
is select empno from emp where deptno = eno;
en emp.empno%type;
begin
open cl2(10);--获取游标中指定参数的数据,需要打开游标时进行声明
loop
fetch cl2 into en;--读取游标的数据存放在
exit when cl2%notfound;--设置退出循环条件
update emp set sal=sal+100 where empno = en;--设置更新sql语句
commit;--增删改需要进行事务提交
end loop;
close cl2;
end;