You can define variable-length arrays, nested tables, and associative arrays in a package.
Usage notes
The collection types that are defined in a package are persisted in the system table. If the package is deleted, the collection types are also deleted.
Examples
See the following example of a conversion between a package collection type and a local collection type:
CREATE OR REPLACE PACKAGE pkg AS
TYPE NumberList IS TABLE OF NUMBER;
PROCEDURE print (nums NumberList);
END pkg;
CREATE OR REPLACE PACKAGE BODY pkg AS
PROCEDURE print (nums NumberList) IS
BEGIN
FOR i IN nums.FIRST..nums.LAST LOOP
RAISE NOTICE '%', nums(i);
END LOOP;
END;
END;
DECLARE
TYPE CharList IS TABLE OF VARCHAR(10);
n1 pkg.NumberList := pkg.NumberList(1,2); -- Use the package collection type.
n2 CharList := CharList('3','4'); -- Use the local collection type.
BEGIN
pkg.print(n1); -- Pass in the variable of the package collection type.
pkg.print(n2); -- Pass in the variable of the local collection type. Type conversion is performed based on the element type.
END;
Sample result:
NOTICE: 1
NOTICE: 2
NOTICE: 3
NOTICE: 4
DO
See the following example of a conversion between a package collection type and a global collection type:
-- Declare the global collection type.
CREATE OR REPLACE TYPE NumList IS TABLE OF NUMBER;
-- Use the package procedure of the previous example.
DECLARE
n NumList := NumList(5,6);
BEGIN
pkg.print(n);
END;
Sample result:
NOTICE: 5
NOTICE: 6
DO