pl/sql 游标变量实例

来源:互联网 发布:ucloud域名备案 编辑:程序博客网 时间:2024/04/29 01:52

参照变量-ref cursor游标变量。
 使用游标时,当定义游标时不需要指定相应的select语句,但是当使用游标时(open时)需要指定select语句,这样一个游标与一个select语句结合了。实例如下:

 1.请使用pl/sql编写一个块,可以输入部门号,并显示部门所有员工的姓名和工资

declare
--定义游标类型 sp_emp_cursor
type sp_emp_cursor is ref cursor;
--定义一个游标变量
test_cursor sp_emp_cursor;
--定义变量
v_ename emp.ename%type;
v_sal emp.sal%type;
begin
--执行
--把test_cursor和一个select结合
open test_cursor for select ename,sal from emp where deptno=&no;
--循环取出
loop
fetch test_cursor into v_ename,v_sal;
--判断test_cursor是否为空
exit when test_cursor%notfound;
dbms_output.put_line('名字:'||v_ename||' 工资:'||v_sal);
end loop;
end;

原创粉丝点击