OraclePL/SQL高级编程(三)

2014-11-24 16:41:48 · 作者: · 浏览: 2
存中的数据也随之变化。

定义游标语法:

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;