下面的例子演示在PL/SQL中如何执行循环结构。
For循环:
set serveroutput on declare l_counter number; begin for l_counter in reverse 1..5 loop dbms_output.put_line('Count is:'||l_counter); end loop; end; /
运行效果:
匿名块已完成 Count is:5 Count is:4 Count is:3 Count is:2 Count is:1
While循环:
set serveroutput on declare l_counter number; begin l_counter := 0; while l_counter<=10 loop dbms_output.put_line('Counter is:'||l_counter); l_counter := l_counter+1; end loop; end; /
运行效果:
匿名块已完成 Counter is:0 Counter is:1 Counter is:2 Counter is:3 Counter is:4 Counter is:5 Counter is:6 Counter is:7 Counter is:8 Counter is:9 Counter is:10
————————————
Done。