Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

associate array declaration

Status
Not open for further replies.

GoTerps88

Programmer
Apr 30, 2007
174
US
Is there a way to declare and assign an associative array in one statement? Every example I've seen uses a separate line of code to assign each index a value. In most programming languages, you can declare and assign in one statement like so:

c#
int[,] nums = {{0,1},{0,2}};

Also is there a way to make an associative array global to a particular package?

Thanks...
 
I want to create an associative array that is indexed by varchar2.

For example, an array of reference codes and reference periods for months of the year.

Code:
TYPE t_referenceperiods IS TABLE OF VARCHAR2(25)
INDEX BY VARCHAR2(25);
v_referenceperiods t_referenceperiods;
v_referenceperiods('M01') := 'January';
 

Try something like this:
Code:
DECLARE
   TYPE t_rp IS TABLE OF VARCHAR2 (25)
      INDEX BY VARCHAR2 (32);
   v_rp   t_rp;
   ix     VARCHAR2 (32);
BEGIN
   v_rp ('First') := 'This is the first.';
   v_rp ('Second') := 'This is the second.';
   ix := v_rp.FIRST;
   FOR x IN 1 .. v_rp.COUNT
   LOOP
      DBMS_OUTPUT.put_line (x || ' = ' || ix || ' - ' || v_rp (ix));
      ix := v_rp.NEXT (ix);
   END LOOP;
END;
/
[3eyes]


----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
To make the associative array global, all you have to do is either declare it in the package spec or at the top of the package body (before any of the procedure or function definitions).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top