← Voltar ao Blog

Working with PL/SQL Collections: Associative Arrays, Nested Tables, and VARRAYs

Publicado em: 23/07/2026 09:15 PL/SQL

📤 Compartilhe este artigo com o link curto:

💼 LinkedIn 🐦 X (Twitter) 👍 Facebook 💬 WhatsApp

Storing and Manipulating Data Sets in Memory

In complex database routines, we often need to temporarily store sets of records or lists of values in memory for procedural processing, business rule validation, or batch manipulation before definitively persisting data to physical tables. To meet this need, PL/SQL provides composite data structures known as Collections.

In this article, we will detail the three types of collections supported by PL/SQL and when to use each to maximize the performance of your procedures and packages.

The Three Types of Collections in PL/SQL

The PL/SQL ecosystem offers three distinct collection structures, each with its own characteristics regarding indexing, size, and persistence:

Practical example of declaring and using an Associative Array:

Native Manipulation Methods

PL/SQL provides built‑in functions and procedures (methods) that are extremely useful for inspecting and manipulating the state of collections at runtime:

Practical example populating a Nested Table with EXTEND:

Performance Best Practices

  1. Prefer Associative Arrays for fast local processing: If you only need an in‑memory dictionary within the procedure to cross‑reference data without persisting to tables, integer‑indexed associative arrays offer excellent performance.
  2. Be careful with PGA consumption: As with BULK COLLECT, avoid unnecessarily loading massive collections with hundreds of thousands of rows into procedural memory to avoid impacting the session PGA.

Conclusion

Mastering the use of collections and arrays in PL/SQL empowers the developer to structure complex, clean, and highly efficient procedural algorithms directly in the database layer.