PL/SQL - Associative Arrays (Index-By Tables) - Table Of Indexed By - Map

> Procedural Languages > PL/SQL - (Procedure Language|PL) SQL

1 - About

An associative array (also called an index-by table) is a map structure (set of key-value pair) implemented with the “table of index by” keyword

Advertising

3 - Syntax

TYPE table_of_type IS TABLE OF VARCHAR2(30) ; -- default indexed by integer  -- List of Called a Nested table

Syntax

4 - Characteristic

  • Each key is unique
  • The key can be either an integer or a string.

5 - Example

SET serveroutput ON;
DECLARE
  TYPE filter_map_type IS TABLE OF VARCHAR2(30) INDEX BY VARCHAR2(30);
  filter_map filter_map_type;
  key_map VARCHAR2(30);
BEGIN
 
filter_map('Hello Key') := 'Hello Value';
filter_map('Hello Key 2') := 'Hello Value 2';
filter_map('Hello Key') := 'Hello Value 3';
 
key_map := filter_map.FIRST; 
WHILE key_map IS NOT NULL LOOP
 
   DBMS_OUTPUT.Put_Line('element(' || key_map || '): ' || filter_map(key_map));
   key_map := filter_map.NEXT(key_map);
 
END LOOP;
END;
/
PL/SQL procedure successfully completed.

element(Hello Key): Hello Value 3
element(Hello Key 2): Hello Value 2
lang/plsql/table_of_index_by.txt · Last modified: 2018/10/24 18:50 by gerardnico