$dbh->do("DECLARE csr CURSOR WITH HOLD FOR SELECT * FROM large_table order by id"); while (1) { my $sth = $dbh->prepare("fetch 100000 from csr"); $sth->execute; my $res = $sth->fetchall_arrayref({}); if ($res && @{$res}) { # batch process the 100k rows } else { # error or no more rows exit; } }