Home » SQL & PL/SQL » SQL & PL/SQL » How to initialize array (oracle )
How to initialize array [message #428927] Fri, 30 October 2009 15:43 Go to next message
yurkoz
Messages: 26
Registered: September 2009
Location: bronx
Junior Member
I have short question . I wrote code

declare

TYPE t_varray IS VARRAY(300) OF NUMBER;

va t_varray := t_varray(
1,1,1,1,1,1,1,1,1,1
);

begin

for j in 1..10 loop
va(j) := j;
dbms_output.put_line('Init '||to_char(j)||' is: '||to_char((j)));

end loop;
end;
/

Code is working

My question can I do the same logic without typing 10 times
1,1,1,1,1,1,1,1,1,1 in declaration of t_varray ?
( because if I did not , I get an error Subscript beyond count)

Thanks for help



Re: How to initialize array [message #428929 is a reply to message #428927] Fri, 30 October 2009 15:58 Go to previous messageGo to next message
Its_me_ved
Messages: 979
Registered: October 2009
Location: India
Senior Member
Here is a useful link that might help



SQL> ed
Wrote file afiedt.buf

  1  DECLARE
  2  TYPE table_type IS varray(10) OF number;
  3  my_table table_type := table_type();
  4  BEGIN
  5  my_table.EXTEND(10);
  6  --my_table(3) := 1;
  7  FOR I IN 1..MY_TABLE.COUNT
  8  LOOP
  9  my_table(i) := 1;
 10  dbms_output.put_line(my_table(i));
 11  END LOOP;
 12* END;
SQL> /
1
1
1
1
1
1
1
1
1
1

PL/SQL procedure successfully completed.

[Updated on: Fri, 30 October 2009 17:01]

Report message to a moderator

Re: How to initialize array [message #428933 is a reply to message #428929] Fri, 30 October 2009 18:16 Go to previous message
yurkoz
Messages: 26
Registered: September 2009
Location: bronx
Junior Member
thank you Its_me_ved.
Previous Topic: list of max open connections
Next Topic: Query
Goto Forum:
  


Current Time: Sun Sep 25 11:10:49 CDT 2016

Total time taken to generate the page: 0.21099 seconds