Serially Reusable Packages : Package Variables « Function Procedure Packages « Oracle PL/SQL Tutorial






SQL> CREATE OR REPLACE PACKAGE myPackage
  2  IS
  3    PRAGMA SERIALLY_REUSABLE;
  4    num_var NUMBER;
  5    char_var VARCHAR2(20);
  6    PROCEDURE initialize;
  7    FUNCTION display_num RETURN NUMBER;
  8    FUNCTION display_char RETURN VARCHAR2;
  9  END myPackage;
 10  /

Package created.

SQL> CREATE OR REPLACE PACKAGE BODY myPackage
  2  IS
  3    PRAGMA SERIALLY_REUSABLE;
  4    PROCEDURE initialize
  5    IS
  6    BEGIN
  7      num_var :=100;
  8      char_var :='Test String1';
  9    END;
 10    FUNCTION display_num RETURN NUMBER
 11    IS
 12    BEGIN
 13      RETURN (num_var);
 14    END;
 15    FUNCTION display_char RETURN VARCHAR2
 16    IS
 17    BEGIN
 18      RETURN (char_var);
 19    END;
 20  END myPackage;
 21  /

Package body created.

SQL> DECLARE
  2    v_num NUMBER;
  3    v_char VARCHAR2(20);
  4  BEGIN
  5    myPackage.initialize;
  6    v_num :=myPackage.display_num;
  7    v_char :=myPackage.display_char;
  8    dbms_output.put_line(TO_CHAR(v_num)||' '||v_char);
  9  END;
 10  /
100 Test String1

PL/SQL procedure successfully completed.

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