Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: ARRAY in PL/SQL ???

Re: ARRAY in PL/SQL ???

From: Erik <ecotsonas_at_saraswati.com>
Date: Thu, 24 Jun 1999 14:13:14 GMT
Message-ID: <7ktedf$6sp$1@nnrp1.deja.com>


In article <37702A72.D862CF1E_at_sftw.umac.mo>,   d951686_at_sftw.umac.mo wrote:
> Hello,
>
> Is it possible to define an ARRAY that can store differnt data type of
> data.
>
> Such as,
>
> declare
> TYPE myArray IS TABLE of some_description INDEX BY BINARY_INTEGER;
> array myArray;
> begin
> array(1) := 'Hello PL/SQL';
> array(2) := 123;
> array(3) := 456.789;
> end;
>
> Is it possible to implemment this ????
>
> Best regards,
> Eric
>

You can't decleare an array like that, but you can create a record data type such as:

  type customer_rectype is record

    ( cust_id       number(5),
      cust_name     varchar2(50),
      cust_birth_dt date

    );

And then create a table of those records like this:

  type customer_recs_tabtype is table of customer_rectype index by binary_integer;

  customer_recs customer_recs_tabtype;

Then you can populate the records like this:

So here is the an example procedure:



CREATE OR REPLACE PROCEDURE TEST_ARRAY IS   type customer_rectype is record
    (cust_id       number(5),
     cust_name     varchar2(50),
     cust_birth_dt date

    );

  type customer_recs_tabtype is table of customer_rectype index by binary_integer;
  customer_recs customer_recs_tabtype;

BEGIN

   for i in 1..customer_recs.count loop

     dbms_output.put_line('*** Record ' || i || ' ***');
     dbms_output.put_line('CustID:   ' || customer_recs(i).cust_id);
     dbms_output.put_line('CustName: ' || customer_recs(i).cust_name);
     dbms_output.put_line('CustBirth: ' || customer_recs
(i).cust_birth_dt);
	 dbms_output.put_line(chr(10));

   end loop;

END TEST_ARRAY;


--
Erik
Consultant
Saraswati Systems Corporation - (SSC)

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't. Received on Thu Jun 24 1999 - 09:13:14 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US