Sunday 15 January 2012

oracle - FOR LOOP IN PL/SQL BLOCK -


Please tell me about receiving 'aa' BB 'CC' with the question below

  is the varray (3) of declared type arrays1 varchar2 (30); A1 arrays1: = arrays1 ('a', 'b', 'c'); Type arrays2 varre (3) varchar2 (30); A2 arrays2: = arrays2 ('a', 'b', 'c'); I will start in 1. 1.a1.count for loop 1. in ja 1. 2. Insert the cube loop dummy_intern values ​​(concat (A1 (I), A2 (j))); Committed; End loop; End loop; End;   

Now I am getting 9 rows

"Now I am getting 9 rows"

External loop phase through an array of three elements nested loop phase through an array of three elements for each element in the outer loop. 3 * 3 = 9

"How to get 'AA' BB 'CC' from the question below

Apply the Okamas razor and discard the internal loop:

  declare type arrays are varray (3) of varchar2 (30); a1 arrays1: = arrays1 ('a', 'b', 'c'); i start at 1. i1 Enter the .count loop in dummy_insert values ​​(concat (A1 (I), A1 (I)); end loop; committed; end;   

Please note that the loop It is wrong behavior. It is obvious that this kind of code is a piece of toy There is no difference, but if we always do the right thing then we will not do the wrong thing when it really matters.

No comments:

Post a Comment