Package level cursor variable : Package Variables « Function Procedure Packages « Oracle PL/SQL Tutorial






SQL>
SQL> CREATE TABLE employee (
  2   employee_id NUMBER(38,0)
  3  ,deptno NUMBER(3,0) NOT NULL
  4  ,first_name  VARCHAR2(95) NOT NULL
  5  ,last_name   VARCHAR2(95) NOT NULL
  6  ,salary NUMBER(11,2)
  7  );

Table created.

SQL>
SQL>
SQL> CREATE OR REPLACE PACKAGE onecur
  2  IS
  3     CURSOR onerow (employee_id_in IN employee.employee_id%TYPE) IS
  4        SELECT * FROM employee WHERE employee_id = employee_id_in;
  5
  6     PROCEDURE open_onerow(employee_id_in IN employee.employee_id%TYPE,close_if_open IN BOOLEAN := TRUE);
  7     PROCEDURE close_onerow;
  8  END onecur;
  9  /

Package created.

SQL> CREATE OR REPLACE PACKAGE BODY onecur IS
  2     PROCEDURE open_onerow (employee_id_in IN employee.employee_id%TYPE,close_if_open IN BOOLEAN := TRUE)
  3     IS
  4        v_close BOOLEAN := NVL (close_if_open, TRUE);
  5        v_open BOOLEAN := TRUE;
  6     BEGIN
  7        IF onerow%ISOPEN AND v_close
  8        THEN
  9           CLOSE onerow;
 10        ELSIF onerow%ISOPEN AND NOT v_close
 11        THEN
 12           v_open := FALSE;
 13        END IF;
 14        IF v_open THEN
 15           OPEN onerow (employee_id_in);
 16        END IF;
 17     END;
 18
 19     PROCEDURE close_onerow IS
 20     BEGIN
 21        IF onerow%ISOPEN
 22        THEN
 23           CLOSE onerow;
 24        END IF;
 25     END;
 26  END onecur;
 27  /

Package body created.

SQL>
SQL> drop table employee;

Table dropped.

SQL>
SQL>








27.12.Package Variables
27.12.1.Package constant variable
27.12.2.Cursor variable in a package
27.12.3.Serially Reusable Packages
27.12.4.Test unit for package scopes
27.12.5.Define constant in a package
27.12.6.Package level cursor variable
27.12.7.Use function to initialize the package level variable
27.12.8.Pre-filled table collection of varchars in a package
27.12.9.Private field
27.12.10.Use package to define variable and use across code blocks
27.12.11.Demonstrate using a packaged ref cursor for passing sets