Oracle loop Statement 1. Exit When LOOP: www.2cto.com SQL code declare -- Local variables here I integer; begin I: = 0; LOOP Exit When (I> 5); Dbms_Output.put_line (I ); i: = I + 1; end loop; end; 2. Loop Java code declare -- Local variables here I integer; begin I: = 0; loop I: = I + 1; dbms_output.put_line (I); if I> 5 then exit; end if; end loop; end; www.2cto.com 3. While loop: SQL code declare -- Local variables here I integer; begin I: = 0; while I <5 loop I: = I + 1; dbms_output.put_line (I); end loop; end; 4. For general loop: SQL code declare -- Local variables here I integer; begin I: = 0; for I in 1 .. 5 loop dbms_output.put_line (I); end loop; end; www.2cto.com 5. For cursor loop: Prepare the data SQL code -- create table test (id number ); -- insert data declare -- Local variables here I integer; begin I: = 0; for I in 1 .. 5 loop insert into test values (I); end loop; www.2cto.com end; loop SQL code declare -- Local variables here begin for c_test in (select * from test) loop dbms_output.put_line (c_test.id ); end loop; end;