-- loop-exs.sql
-- last modified: 1-30-13
--------
-- signature: procedure: loopy: void -> void
-- purpose: expects nothing, and returns nothing, but displays
-- to the screen the results printed by a pair of loops,
-- to demonstrate PL/SQL basic loops
--
-- example: when run, if serveroutout is on, you should see:
-- BURP! 0
-- BURP! 1
-- BURP! 2
-- BURP! 3
-- BURP! 4
-- GLIP! 13
-- GLIP! 14
-- GLIP! 15
-- GLIP! 16
--
-- by: Sharon Tuttle
-- last modified: 01-30-13
create or replace procedure loopy as
limit integer;
counter integer;
begin
-- demonstrate a PL/SQL while loop
counter := 0;
limit := 5;
while counter < limit
loop
dbms_output.put_line('BURP! ' || counter);
counter := counter + 1;
end loop;
-- demonstrate a PL/SQL counted/for loop
for counter in 13 .. 16
loop
dbms_output.put_line('GLIP! ' || counter);
end loop;
-- tried several variants on an Algol-style for-loop
-- with a list of values, then Googled and found Oracle's
-- doc for at
-- http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/loop_statement.htm
-- ...doesn't look like PL/SQL supports that variant;
end;
/
show errors
set serveroutput on
prompt
prompt TESTING: should see BURP! followed by 0-4, and GLIP! followed
prompt by 13-16
prompt ===========================================================
exec loopy
prompt
prompt ...and should see it again (testing the call with () )
prompt ===========================================================
exec loopy()
-- end of loop-exs.sql