-----------------------------------------------------------------
-- PL/SQL: Cursor example (Section 4.6.1)                       -
-- Chapter 4; Oracle Programming -- A Primer                    -
--            by R. Sunderraman                                 -
-----------------------------------------------------------------

  DECLARE
    CURSOR c1 IS
      select cno,cname,city
      from   customers,zipcodes
      where  customers.zip = zipcodes.zip;

    c1_rec c1%rowtype;

  BEGIN
    if not c1%isopen then
      open c1;
    end if;

    fetch c1 into c1_rec;
    while c1%found loop
      dbms_output.put_line('Row Number ' || c1%rowcount || '> ' ||  
        c1_rec.cno || '  ' || c1_rec.cname || '  ' || c1_rec.city);
      fetch c1 into c1_rec;
    end loop;

  END;
/
