参照变量
用于存放数值指针的变量,通过使用参照变量可以使应用程序共享相同对象,从而降低占用的空间可以使用游标变量(ref cursor)和对象类型变量(ref obj_type)两种参照变量
使用游标时,当定义游标不需要指定相应的select语句,但是当使用游标时(open时)需要指定select语句
实例如下:
1.编写pl/sql块 可以输入部门号,并显示部门所有的员工姓名和工资
declare
--定义游标类型sp_emp_cursor
type sp_emp_cursor is ref cursor;
--定义游标变量
emp_cursor sp_emp_cursor;
--定义变量
v_name emp.name%type;
v_sal emp.sal%type;
begin
--执行部分
--把emp_cursor和一个select语句结合
open emp_cursor for select name,sal from emp where deptno=&no;
--循环取数据
loop
fetch emp_cursor into v_name,v_sal;
--判断emp_cursor 为空则退出
exit when emp_cursor%notfound;
dbms_output.put_line('姓名是:'||v_name||'工资是:'||v_sal);
end loop;
--关闭游标
close emp_cursor;
end;
/