use DBI;

$drh = DBI->install_driver( 'Oracle' );
$dbh = $drh->connect( $ARGV[1], $ARGV[2], $ARGV[3] );

die $drh->errstr unless $dbh; 

$i = 0;

foreach $table ($dbh->tables()) {
    next unless ($table =~ /^SYSBHA\./ && $table !~ /_SEQ$/);

    $i++;

    $cursor = $dbh->prepare("select * from $table");
    die "($table) ".$dbh->errstr unless $cursor;
    $cursor->execute();

    @columns = @{$cursor->{NAME_uc}};
    
    $cursor1 = $dbh->prepare("select count(*) from (select * from $table)");
    die "($table count) ".$dbh->errstr unless $cursor1;
    $cursor1->execute();
    ($rows) = $cursor1->fetchrow();
    $cursor1->finish();
    $cursor1 = undef;	# <=== Comment out this line and it works OK
    print "$i: $table - $rows\n";
  
    while ( @row = $cursor->fetchrow() ) {
	# Do nothing
    }

    $cursor->finish();
    $cursor = undef;
}

$dbh->disconnect;
