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: Thomas Kyte <tkyte_at_us.oracle.com>
Date: 1998/03/15
Message-ID: <350e446d.19370743@192.86.155.100>#1/1

A copy of this was sent to mouyang_at_yahoo.com (if that email address didn't require changing) On Sat, 14 Mar 1998 21:40:23 -0600, you wrote:

>Hi all,
>
>I want to use arrays in PL/SQL. Is there any way to implement a pseudo
>array or implement variables act as array?
>
>Thanks for any help.
>
>Ouyang
>
>-----== Posted via Deja News, The Leader in Internet Discussion ==-----
>http://www.dejanews.com/ Now offering spam-free web-based newsreading

PL/SQL table types are very much like a sparse array. They can be subscripted from -2^31 to 2^31. for example:

declare

   type dateArray is table of date index by binary_integer;    myDateArray dateArray;
   idx number;
begin

   myDateArray(5) := sysdate;
   myDateArray(10) := sysdate-1;
   myDateArray(15) := sysdate+1;

   idx := myDateArray.first;
   loop

       dbms_output.put_line( idx || ' - ' || myDateArray(idx) );
       exit when idx = myDateArray.last;
       idx := myDateArray.next(idx);   

   end loop;
end;

(above uses 7.3 attributes .first, .next, .last on tables... In 7.2 and before you need to remember the indices yourself)  

Thomas Kyte
tkyte_at_us.oracle.com
Oracle Government
Herndon VA  

http://govt.us.oracle.com/ -- downloadable utilities  



Opinions are mine and do not necessarily reflect those of Oracle Corporation  

Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it. Received on Sun Mar 15 1998 - 00:00:00 CST

Original text of this message

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