Menu

1 / 2

GBase 8s Nested Tables: A Practical Guide to Collection Types

DEV Community·Michael·6 months ago
#c9NRYCFw
#gbase#database#software#coding#table
Reading 0:00
15s threshold

GBase 8s supports Oracle‑compatible PL/SQL when the environment variable SQLMODE is set to 'ORACLE' . Among the three collection types available, nested tables are unique: their element count is unspecified, their index type is integer, and they can be defined locally inside a PL/SQL block or globally as a database object.

Syntax

Local definition: TYPE type_name IS TABLE OF datatype;

Global definition: CREATE TYPE type_name IS TABLE OF datatype;

Characteristics

Must be initialized before use — an uninitialized nested table is NULL.

Elements are stored in no particular order.

Indexes start at 1 .

Memory can grow and shrink dynamically as elements are added or removed.

Example: Nested Table vs Associative Array as OUT Parameters

The following package defines two procedures — one using a nested table, the other an associative array indexed by VARCHAR(5) — to illustrate how they are declared, populated, and called.

-- Base table DROP TABLE IF EXISTS tab1 ; CREATE TABLE tab1 ( id INT , name VARCHAR (…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.