2016-6-7
隐式游标:不需要显示定义即可使用的游标
专门处理select into ,insert ,delete ,update 等语句
属性:
sql%found :fetch语句是否获取到了结果
sql%isopen :游标是否处于打开的状态
sql%notfound :fetch预计不是否没有获取到了结果
sql%rowcount :受影响的行数
显示游标:
声明 cursor cursor_name is select_statement;
打开 open cursor_name;
获取数据 fetch cursor_name into variable;
关闭 close cursor_name;
属性:
%found :fetch 语句是否获取到了结果
%isopen : 游标 是否处于打开的状态
%notfound :fetch语句是否没有获取到了结果
%rowcount :游标中记录的行数。
游标是一行一行的读取数据
使用方式:
declare
CURSOR cur(dno NUMBER) is SELECT * from emp where DEPTNO=dno;
begin
for r in cur(10) loop
SYS.DBMS_OUTPUT.PUT_LINE(r.ename || ':' || r.sal || ':' || r.deptno);
end loop;
end;
标准方式
declare
CURSOR cur(dno NUMBER) is SELECT * from emp where DEPTNO=dno;
v_row cur%rowTYPE;
begin
open cur(10) ;
LOOP
exit when cur%notfound;
fetch cur into v_row;
DBMS_OUTPUT.PUT_LINE(v_row.ename || ':' || v_row.sal || ':' || v_row.deptno);
end loop;
close cur;
end;