On 11/16/05, Rob Craig <[EMAIL PROTECTED]> wrote: > I am using DBD::mysql and I can get the number of rows by assigning the > result of the execute to a scalar: > > my $rows = $sth->execute or die "Couldn't execute statement: " . > DBI->errstr; > > maybe this doesn't work with DBD::Oracle? > > Rob
When you execute a SELECT statement in MySQL, it (by default) immediately returns all of the rows back to you under the covers, which is why it is able to give you a row count. Woe betide you if your SELECT statement returns a million rows. > > [EMAIL PROTECTED] wrote: > #Here's an example which shows what I am trying to accomplish. If I > can determine the number of rows before pushing the data, this can > simply things for #me when processing the data throught my scripts. > # > use warnings; > use strict; > use DBI; > use DBD::Oracle; > > my $sql=q{ select name, location > from mytable > }; > > my $dbh; > > eval { > $dbh = DBI->connect("dbi:Oracle:MYDB", > 'dbuser', 'dbpass', > { > RaiseError => 1, > AutoCommit => 0, > ora_session_mode => 0 > } > ); > }; > > if ( $@ ) { > outprint('end',"$DBI::errstr\n"); > } > > my $sth=$dbh->prepare($sql) or die "Couldn't prepare statement: " . DBI- > > > errstr; > > $sth->execute or die "Couldn't execute statement: " . DBI->errstr; > > my $ary; > > while ($ary = $sth->fetchrow_array()) { > #I need to determine number of rows as this will affect > whether a matrix is used or not > #a boolean variable $matrix could be returned or a ref > check done so that the data > #processing code can act accordingly > #$sth->rows only shows total rows after the while loop > is processed > #Can I accomplish this without a seperate count(*) > statement? > # > #push @newary,[ @{$ary} ]; # if more than one row > #or > #push @newary, @{$ary} ; # single row > } > > $sth->finish; > > $dbh->disconnect; > # > #ActivePerl 5.8.7 813 > #ppm > #-DBD-Oracle 1.16 > #-DBI 1.48 > > > > > No virus found in this outgoing message. > Checked by AVG Free Edition. > Version: 7.1.362 / Virus Database: 267.13.3/173 - Release Date: 11/16/2005 > > >