Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 7

Advanced PLSQL Concepts

Pune

What we cover ?
Ref Cursors

Collections

Collections
A collection is a composite type which combines variables of the same type as a

single unit.
Similar to a C or Java Array. There are 3 collection types:
-Index by tables -Nested Tables -Varrays

PLSQL Tables
Index by tables and nested tables are collectively known as PLSQL tables.

Nested tables can be stored in a in Database Tables and can be manipulated


using SQL. Index by tables exist entirely in PLSQL and cannot be stored directly in a database table. PLSQL Tables have no declared upper limit.

Index by Tables
To declare a Index by table, we first declare a table type in a PLSQL block and

then declare a variable of this type.


TYPE tabletype IS TABLE OF type INDEX BY BINARY_INTEGER. It Consists of 2 columns of which first column consist of binary integer. Second column consists of value of specified data type. Once the type and variable are declared, we can refer to the individual elements in the PLSQL table using the syntax: tablename(index). When a table is created of record type, we can refer to fields within the record

with syntax: table(index).field.

Nested Tables
Same as index by tables.

Nested tables must be created with sequential keys, and the keys cannot be
negative. Syntax: TYPE table_name is TABLE OF table_type [NOT NULL] If NOT NULL is present,elements of the nested table cannot be null Nested table needs to be initialized. Initialization is done using Constructor. The constructor of nested table will have the same name as of table type itself. However, it can have varying number of

arguments.
The arguments become elements of the table starting sequentially with index 1.

V Arrays(Variable Arrays)
V array has a fixed upper bound on its size, specified as a part of the declaration.

Syntax: TYPE type_name IS {VARRAY| VARYING ARRAY} (max size) OF


element_type [NOT NULL] Needs to be initialized using a constructor. The no.of arguments passed to the constructor becomes the initial length of the Varray andd must be less than or equal to the maximum length specified in the VARRAY type.

You might also like