示例16 程序包中的动态游标

本文深入探讨了Oracle PL/SQL程序包中动态游标的使用,包括如何创建、使用和关闭动态游标,以及其在数据库操作中的优势。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/*============================================================
                        程序包中的动态游标
  ============================================================*/

create or replace package emp_cursorPack is
  type type_emp_cursor is ref cursor;
  --cur1 type_emp_cursor; 不可以 
  PROCEDURE proc_emp(cur OUT type_emp_cursor);
end emp_cursorPack;

--创建程序包主体,返回员工薪水结果集
CREATE OR REPLACE PACKAGE BODY emp_cursorPack  is 
    --cur1 type_emp_cursor; 不可以 
    PROCEDURE proc_emp(cur OUT type_emp_cursor) IS
    BEGIN
      OPEN cur FOR
      SELECT empno,sal FROM emp;
    END;
END;

--调用emp_cursorPack.proc_emp存储过程,显示员工薪水
DECLARE
  v_empno  emp.empno%type;
  v_sal emp.sal%type;
  emp_salary  emp_cursorPack.type_emp_cursor;
BEGIN
  emp_cursorPack.proc_emp(emp_salary);
  LOOP
    FETCH emp_salary INTO v_empno, v_sal;
    EXIT WHEN emp_salary%notfound;
    DBMS_OUTPUT.PUT_LINE(v_empno||'的薪水是' ||v_sal);
  END LOOP;
  CLOSE emp_salary;
END;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值