René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

Static cursors in PL/SQL

set serveroutput on;

create table test_for_cursor (
  a   varchar2(10),
  b   number
);

insert into test_for_cursor values ('one',   1);
insert into test_for_cursor values ('two',   2);
insert into test_for_cursor values ('three', 3);
insert into test_for_cursor values ('four',  4);
insert into test_for_cursor values ('five',  5);

commit;

declare
  cursor cur_t is select * from test_for_cursor;
  
  rec_t test_for_cursor%rowtype;
begin
  open cur_t;
  loop
    fetch cur_t into rec_t;
    exit when cur_t%notfound;
    dbms_output.put_line('a: ' || rec_t.a || ', b: ' || rec_t.b);
  end loop;
end;
/

drop table test_for_cursor;

Links