-- loop-exs.sql -- last modified: 2016-01-29 /*----- procedure: loopy: void -> void purpose: expects nothing, returns nothing, and if set serveroutput on, prints to the screen the results of several example loops example: if set serveroutput on, and you run loopy, and you have the usual dept table from set-up-empl-tbls.sql, the following should be printed to the screen: BURP! 0 BURP! 1 BURP! 2 BURP! 3 BURP! 4 GLIP! 13 GLIP! 14 GLIP! 15 GLIP! 16 Name: Accounting Name: Research Name: Sales Name: Operations Name: Management by: Sharon Tuttle last modified: 2016-01-29 -----*/ create or replace procedure loopy as limit integer; counter integer; begin -- demo a PL/SQL while loop counter := 0; limit := 5; while counter < limit loop dbms_output.put_line('BURP! ' || counter); counter := counter + 1; end loop; -- demo a PL/SQL for loop/count-controlled loop for counter in 13 .. 16 loop dbms_output.put_line('GLIP! ' || counter); end loop; -- demo a PL/SQL cursor-controlled loop for next_row in (select * from dept) loop dbms_output.put_line('Name: ' || next_row.dept_name ); end loop; end; / show errors