Creating an APEX collection

APEX collections can be useful for storing temporary data in an array like structure.

This example shows how to create an APEX collection called TEST_COLLECTION. The name is unique to the user’s┬ásession.

apex_collection.collection_exists does exactly what you would expect it to do. There’s no point in creating it if it doesn’t exist, so check for it’s existence first. Also, you don’t want to truncate the collection if you’ve already stored data in there.

if not apex_collection.collection_exists(p_collection_name=>'TEST_COLLECTION') then
  APEX_COLLECTION.CREATE_OR_TRUNCATE_COLLECTION(p_collection_name => 'TEST_COLLECTION');
end if;

The next step after creating it would be to add rows to the collection.

2 thoughts on “Creating an APEX collection”

Leave a Reply