参照变量【PL/SQL】

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xky1306102chenhong/article/details/82721025

参照变量是指用于存放数值指针的变量。

1. 游标变量

-- 输入部门号,并显示该部门所有员工的姓名和他的工资
declare
--定义游标类型
type ch_emp_cursor is ref cursor;
--定义游标变量
test_cursor ch_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;
 --关闭游标
 close test_cursor;
end;

2. 对象类型变量

猜你喜欢

转载自blog.csdn.net/xky1306102chenhong/article/details/82721025