pl/SQL编程(五)参照变量

参照变量
用于存放数值指针的变量,通过使用参照变量可以使应用程序共享相同对象,从而降低占用的空间可以使用游标变量(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;
/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值