Skip Headers
Oracle® Database PL/SQL Language Reference
11g Release 2 (11.2)

Part Number E10472-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

Collection

A collection groups elements of the same type in a specified order. Each element has a unique subscript that determines its position in the collection.

PL/SQL has three kinds of collections:

Associative arrays can be indexed by either integers or strings. Nested tables and varrays are indexed by integers.

To create a collection, you first define a collection type, and then declare a variable of that type.

Note:

This topic applies to collection types that you define inside a PL/SQL block or package, which are different from standalone stored collection types that you create with the "CREATE TYPE Statement".

In a PL/SQL block or package, you can define all three collection types. With the CREATE TYPE statement, you can create nested table types and varray types, but not associative array types.

Topics:

Syntax

collection_type_definition ::=

collection_type_definition
Description of the illustration collection_type_def.gif

assoc_array_type_def ::=

assoc_array_type_def
Description of the illustration assoc_array_type_def.gif

See element_type ::=.

nested_table_type_def ::=

nested_table_type_def
Description of the illustration nested_table_type_def.gif

See element_type ::=.

varray_type_def ::=

varray_type_def
Description of the illustration varray_type_def.gif

See element_type ::=.

collection_variable_dec ::=

collection_variable_dec
Description of the illustration collection_variable_dec.gif

element_type ::=

element_type
Description of the illustration element_type_definition.gif

Semantics

assoc_array_type_def

The type definition for an associative array.

Restriction on assoc_array_type_def The type definition of an associative array can appear only in the declarative part of a block, subprogram, package specification, or package body.

collection_name

The name of the collection variable that you are declaring.

data_type

A data type specified with either %ROWTYPE or %TYPE that represents either PLS_INTEGER, BINARY_INTEGER, or VARCHAR2(v_size). See datatype ::=.

element_type

The data type of the collection element (any PL/SQL data type except REF CURSOR).

In nested_table_type_def:

INDEX BY

Specifies the data type of the indexes of the associative array—PLS_INTEGER, BINARY_INTEGER, VARCHAR2(v_size) or data_type.

nested_table_type_def

The type definition for a nested table.

NOT NULL

Specifies that no element of the collection can have the value NULL.

size_limit

A positive integer literal that specifies the maximum number of elements that the varray can have. The maximum value of size_limit is 2147483647.

type_name

The name of the collection type that you are defining.

v_size

The length of the VARCHAR2 key by which the associative array is indexed.

varray_type_def

The type definition for a variable-size array.

Examples

Related Topics

In this chapter:

In other chapters: