Home » RDBMS Server » Server Administration » How do declare an Array in PL/SQL
How do declare an Array in PL/SQL [message #58363] Tue, 19 August 2003 09:42 Go to next message
sidd
Messages: 130
Registered: May 2003
Senior Member
How do declare an Array in PL/SQL, like u declare in c or c++ i want to declare an Array of Integer type of length 200, how do i do that in pl/sql?
Re: How do declare an Array in PL/SQL [message #58370 is a reply to message #58363] Wed, 20 August 2003 00:20 Go to previous message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
Here's the Online documentation concerning collections.

The principle's this:
-- declare a varray type:
TYPE <I>type_name</I> IS VARRAY(<I>size_limit</I>) OF <I>datatype</I>;
your_varray type_name; -- declare a variable of this type and initialize it.
Datatype can be a simple data_type, but also a %TYPE, a %ROWTYPE a previously defined record type or SQL type... I'd suggest you read the docs carefully.

Here's what I do when I need a varray. I declare a PL/SQL index by table (no upper bound and no need to initialize it):
SQL> declare
  2    type tab_type is table of integer index by binary_integer;
  3    my_table tab_type;
  4  begin
  5    for i in 1..12
  6    loop
  7      my_table(i) := i*i;
  8    end loop;
  9    for j in 1..my_table.count
 10    loop
 11      dbms_output.put_line(my_table(j));
 12    end loop;
 13* end;
 14  /
1
4
9
16
25
36
49
64
81
100
121
144

PL/SQL procedure successfully completed.

SQL> 
HTH,
MHE
Previous Topic: Sequences and Performance
Next Topic: about job operation in oem
Goto Forum:
  


Current Time: Fri Sep 20 06:32:45 CDT 2024