TYPE a_places_i_lived IS TABLE OF VARCHAR2(50) INDEX BY VARCHAR2(10);
No link seguinte têm um exemplo completo.
http://it.toolbox.com/blogs/oracle-guide/minitip-3-associative-array-retrieve-and-sort-array-index-11185
E se quizerem devoler os dados na ordem inversa:
E se quizerem devoler os dados na ordem inversa:
DECLARE -- Declare the table TYPE a_places_i_lived IS TABLE OF VARCHAR2 (50) INDEX BY VARCHAR2 (10); --declare my table variable v_places_i_lived a_places_i_lived; -- Declare a temporary holding variable v_current VARCHAR2 (10); BEGIN -- Initialize the array in unsorted order v_places_i_lived ('LA') := 'New Orleans'; v_places_i_lived ('FL') := 'Tampa'; v_places_i_lived ('TX') := 'San Antonio'; v_places_i_lived ('CA') := 'Los Angeles'; v_places_i_lived ('CT') := 'New Haven'; --starts from the end v_current := v_places_i_lived.LAST; LOOP -- Exit when we hit the bottom of the table EXIT WHEN v_current IS NULL; -- Print out DBMS_OUTPUT.put_line ('Index is: ' || v_current||' Value is: ' || v_places_i_lived (v_current)); -- delete the current v_places_i_lived.delete(v_current); v_current := v_places_i_lived.LAST; END LOOP; END;
Sem comentários:
Enviar um comentário