Databases Reference
In-Depth Information
C H A P T E R 10
Working with APEX Collections
by Raj Mattamal
When writing applications, developers often need a way to store an unknown number of items in a
temporary structure. The most pervasive example of this is the online shopping cart. When a user
browses an online store, one doesn't know the number of items the user intends to purchase. To address
this, application developers use collections to store these variable pieces of data.
The term collections itself is a rather general one. Many, if not most, programming techniques offer
some method of storing variable collection-type data, and terms such as arrays , sets , and lists are
common across them. In Oracle PL/SQL, the need to store collection data is most commonly met using
constructs such as Nested Tables, Varrays, and Associative Arrays. Unfortunately, these constructs aren't
generally useful across pages of Oracle APEX applications, because they tend to persist for the life of the
given database session, whereas APEX page views can span multiple database sessions.
To address this need to temporarily manage an unknown number of items in an application user
session that might span multiple database sessions, Oracle APEX offers APEX Collections. Much in the
same way that APEX manages the session-related information stored into page- and application-level
items, APEX Collections allow developers to temporarirly store variable amounts of data within a user
session without burdening the developer with the mechanics of session state mangement. What follows
is an exploration of the need for collections, some common use cases, and tips and tricks that use
collections.
When to Use APEX Collections
As already mentioned, APEX Collections provide application delopers an easy way to store variable
amounts of data. When discussing this in the context of database applications, people often ask why the
information shouldn't be stored in temporary tables. The answer to this is simple: APEX web
applications are ultimately stateless, and each page view is generally a distinct database session. As
temporary tables do not persist beyond the current database session, the data gathered from one page
view or process in an APEX application won't be readily available in subsequent ones. It is logical then to
consider using regular database tables to store collection data. In fact, APEX collections are stored in
regular database tables, but the developer does not need to be aware of this. We will take a closer look at
the back-end mechanics of collections later; for now, you can think of APEX Collections almost as
regular tables that are associated with the session of the user currently logged into the application. What
makes collections an excellent choice for storing temporary data in APEX applications, is that APEX
manages the session state of the collections as users click through multiple page views, and by extension
multiple database sessions, without the developer having to mind the underlying concepts. To
appreciate this, it is worthwhile to take a quick look into this extra overhead that APEX manages behind
the scenes.
Search WWH ::




Custom Search