-- cursor-loop-ex.sql
-- last modified: 1-30-13
--
-- uses a table from set-up-ex-tbls.sql

--------
-- signature: procedure: cursor_loop: void -> void
-- purpose: expects nothing, and returns nothing, but does have the
--          side-effect of printing to the screen the names of
--          each department in the dept table, 1 per line, with the
--          help of a simple cursor based on a select statement
-- example: if called while the dept table contains just 2 rows,
--          Accounting and Finance, you'd see printed to the screen:
-- Name: Accounting
-- Name: Finance
--
-- last modified: 1-30-13
-- by: Sharon Tuttle
--------

create or replace procedure cursor_loop as
begin
    -- loop through all the rows in the dept table

    for next in (select *
                 from dept) 
    loop
        -- ...and print the name of the dept in the current row

        dbms_output.put_line('Name: ' || next.dept_name );
    end loop;
end;

/

show errors

set serveroutput on

prompt
prompt TESTING: should see the names of all departments in dept table
prompt ===========================================================
prompt

exec cursor_loop

-- end of cursor-loop-ex.sql