Oracle Database 10g SQL (Osborne ORACLE Press Series)

In this chapter, you will

Introducing Collections

The Oracle8 database introduced two new database types known as collections , which allow you to store sets of elements. The Oracle9 i database extends these features to include multilevel collections, which allow you to create a collection that is itself a collection. The Oracle10 g database further improves collections to include more ANSI functionality along with other enhancements.

There are three types of collections:

You create a collection type using the SQL DDL CREATE TYPE statement, and you then use these types to define columns in a table. The elements stored in a varray are stored with the table when the size of the varray is 4KB or less, otherwise the varray is stored outside of the table. The elements for nested tables are stored in separate tables. When a varray is stored with the table, accessing its elements is faster than accessing elements in a nested table. An associative array is a PL/SQL construct, not a SQL construct. An associative array cannot be stored persistently in a table.

You might be asking yourself why you would want to use collections in the first place. After all, using two tables with a foreign key already allows you to model relationships between data. The answer is that the data stored in the collection may be accessed more rapidly by the database than if you were to use two tables instead. Typically, you ll want to use a collection if you have data that is only used by one table. For example, this chapter uses collections to store addresses for customers, and those addresses are used only within the tables they are stored in.

Категории