sub run_cursor { my ($dbh) = @_; my $sql = " select x as column1 , current_date - x * interval '1 day' as column2 from generate_series(1,25) f(x) "; $dbh->do("DECLARE csr CURSOR WITH HOLD FOR $sql"); # WITH HOLD is not needed if AutoCommit is off while (1) { my $sth = $dbh->prepare("fetch 10 from csr"); $sth->execute; last if 0 == $sth->rows; while (my $row = $sth->fetchrow_arrayref) { for(my$i=0;$i<$sth->{NUM_OF_FIELDS};$i++) { print $sth->{NAME_lc}->[$i], " = " , $row->[$i], "\t"; } print "\n"; } } $dbh->do("CLOSE csr"); }