[Solved] FOR LOOP IN PL/SQL BLOCK [closed]


“Now I am getting 9 rows”

The outer loop steps through an array of three elements. The nested loop steps through an array of three elements for every element in the outer loop. 3 * 3 = 9.

“how to get ‘AA’ ‘BB’ ‘CC’ from below query”

Apply Occam’s razor and discard the inner loop:

declare
   type arrays1 is varray(3) of varchar2(30);
   a1 arrays1 := arrays1('A', 'B', 'C');
begin
   for i in 1..a1.count loop
         insert into dummy_insert  values(concat(a1(i),a1(i)));
   end loop;
   commit;
end;

Please note that committing inside loops is bad practice. Obviously it doesn’t make any difference with a toy piece of code like this, but if we always do the right thing we won’t do the wrong thing when it actually matters.

4

solved FOR LOOP IN PL/SQL BLOCK [closed]