10-2. Creating and Accessing an Indexed Table

Problem

You need to store a group of numbers for later processing in another procedure.

Solution

Create an indexed table using an integer index to reference the elements. For example, this recipe loads values into an indexed table of numbers.

DECLARE TYPE    num_type IS TABLE OF number INDEX BY BINARY_INTEGER; nums    num_type; total   number; BEGIN    nums(1) := 127.56;    nums(2) := 56.79;    nums(3) := 295.34;    -- call subroutine to process numbers;    -- total := total_table (nums); END;

How It Works

PL/SQL tables are indexed collections of data of the same type. The datatype can be any of the built-in datatypes provided by PL/SQL; in this example, the datatype is a number. Here are some ...

Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.