定义游标语法:
cursor 游标名(参数1 数据类型, ….) is select 子句;
打开游标语法:
open游标名(&参数1, ….) ;
案例:从scott方案的emp表中查询并打印某个部门的雇员情况,其中部门号由用户交互式输入。
Accept v_deptnoprompt‘please enter the deptno;
declare
v_ename scott.emp.ename%type;
v_sal scott.emp.sal%type;
cursor emp_cursor (v_deptno number) is selectename,sal from scott.emp where deptno=v_deptno;
begin
open emp_cursor(&p_deptno);
loop
fetch emp_cursor into v_ename,v_sal;
exit when emp_cursor%notfound;
dbms_output.put_line(v_ename|| ' '||v_sal);
end loop;
close emp_cursor;
end;