plsql - How to add values to a VARRAY using a loop -


i have varray , want add elements varray using loop. have tried far.

declare type code_array_  varray(26) of varchar2(6); codes_ code_array_;  begin in 1..26 loop         codes_(i) := dbms_random.string('u',6);   end loop; end; 

above code gives me error

"ora-06531: reference uninitialized collection"

as error message says, need initialise collection variable:

... begin   codes_ := code_array_();   ... 

but need size it, either single extension each time around loop:

  in 1..26 loop         codes_.extend;     ... 

or one-off extension before start:

... begin   codes_ := code_array_();   ...   codes_.extend(26);   in 1..26 loop         ... 

you use post-extend size control loop, save hard-coding 26 again:

declare   type code_array_ varray(26) of varchar2(6);   codes_ code_array_; begin   codes_ := code_array_();   codes_.extend(26);   in 1..codes_.count loop         codes_(i) := dbms_random.string('u',6);   end loop; end; /  pl/sql procedure completed. 

read more collections.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -