FAQ
#!/bin/perl -w
use DBI;
my $db = $ARGV[0];
my $rows;
my $dbh = DBI->connect( "dbi:Oracle:$db", "vprasad", "vprasad" )
or die "Can't connect to Oracle database: $DBI::errstr\n";
my $stamt = $dbh->prepare("select * from ab_tran");
$stamt->execute();

$rows = $stamt->fetchrow_array(); --- without using this function
print "rows: $rows\n";

$stamt->finish;
$dbh->disconnect
or warn "Disconnection failed: $DBI::errstr\n";

Without using the function 'fetchrow_array()' , is there any better way to
get
count of number of rows for a select st.

Regards
Veera Prasad


© 2003 OpenLink Financial

Copyright in this message and any attachments remains with us. It is
confidential and may be legally privileged. If this message is not
intended for you it must not be read, copied or used by you or
disclosed to anyone else. Please advise the sender immediately if
you have received this message in error.

Although this message and any attachments are believed to be free of
any virus or other defect that might affect any computer system into
which it is received and opened, it is the responsibility of the
recipient to ensure that it is virus free and no responsibility
is accepted by Open Link Financial, Inc. for any loss or damage in any
way arising from its use.

Search Discussions

  • Michael A Chase at Apr 3, 2003 at 2:10 am

    On Wed, 2 Apr 2003 16:17:20 -0500 Veera Prasad wrote:


    #!/bin/perl -w
    use DBI;
    my $db = $ARGV[0];
    my $rows;
    my $dbh = DBI->connect( "dbi:Oracle:$db", "vprasad", "vprasad" )
    or die "Can't connect to Oracle database: $DBI::errstr\n";
    my $stamt = $dbh->prepare("select * from ab_tran");
    $stamt->execute();
    It is risky to execute() without checking for success. Either set
    $dbh -> {RaiseErrors} to 1 before prepare()ing, or check each call.
    $rows = $stamt->fetchrow_array(); --- without using this function
    print "rows: $rows\n";
    Read the fine DBI manual to find out what fetchrow_array() returns
    in a scalar context.

    http://trantor.jsbsystems.com/DBI-FAQ/49.html
    $stamt->finish;
    $dbh->disconnect
    or warn "Disconnection failed: $DBI::errstr\n";

    Without using the function 'fetchrow_array()' , is there any better way
    to get count of number of rows for a select st.
    No the best way is to count them as you fetch them. The fetch*()
    methods only fetch a single row, so you'll need a loop.

    --
    Mac :})
    ** I normally forward private questions to the appropriate mail list. **
    Ask Smarter: http://www.catb.org/~esr/faqs/smart-questions.html
    Give a hobbit a fish and he eats fish for a day.
    Give a hobbit a ring and he eats fish for an age.
  • Rudy Lippan at Apr 3, 2003 at 2:36 am

    On Wed, 2 Apr 2003, Michael A Chase wrote:
    On Wed, 2 Apr 2003 16:17:20 -0500 Veera Prasad wrote:

    $stamt->finish;
    $dbh->disconnect
    or warn "Disconnection failed: $DBI::errstr\n";

    Without using the function 'fetchrow_array()' , is there any better way
    to get count of number of rows for a select st.
    No the best way is to count them as you fetch them. The fetch*()
    methods only fetch a single row, so you'll need a loop.
    Michael,

    I am going to be a bit of a pedant here. Don't you mean something more
    like /^fetch(?!all)/ :)

    And of course the fetchall_arrayref could give us a very bloated way of
    getting a count:

    $count = @{$sth->fetchall_arrayref()};


    Later,

    Rudy
  • Vonerden, Gary at Apr 3, 2003 at 3:46 pm
    in the initial sql statement
    could you just add 'count'
    before
    my $stamt = $dbh->prepare("select * from ab_tran");
    after
    my $stamt = $dbh->prepare("select count(*) from ab_tran");

    -----Original Message-----
    From: Veera Prasad
    Sent: Wednesday, April 02, 2003 4:17 PM
    To: dbi-users@perl.org
    Subject: Need to Get the count of number of rows of select st without
    usin g count(*)!



    #!/bin/perl -w
    use DBI;
    my $db = $ARGV[0];
    my $rows;
    my $dbh = DBI->connect( "dbi:Oracle:$db", "vprasad", "vprasad" )
    or die "Can't connect to Oracle database: $DBI::errstr\n";
    my $stamt = $dbh->prepare("select * from ab_tran");
    $stamt->execute();

    $rows = $stamt->fetchrow_array(); --- without using this function
    print "rows: $rows\n";

    $stamt->finish;
    $dbh->disconnect
    or warn "Disconnection failed: $DBI::errstr\n";

    Without using the function 'fetchrow_array()' , is there any better way to
    get
    count of number of rows for a select st.

    Regards
    Veera Prasad


    © 2003 OpenLink Financial

    Copyright in this message and any attachments remains with us. It is
    confidential and may be legally privileged. If this message is not
    intended for you it must not be read, copied or used by you or
    disclosed to anyone else. Please advise the sender immediately if
    you have received this message in error.

    Although this message and any attachments are believed to be free of
    any virus or other defect that might affect any computer system into
    which it is received and opened, it is the responsibility of the
    recipient to ensure that it is virus free and no responsibility
    is accepted by Open Link Financial, Inc. for any loss or damage in any
    way arising from its use.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdbi-users @
categoriesperl
postedApr 2, '03 at 9:14p
activeApr 3, '03 at 3:46p
posts4
users4
websitedbi.perl.org

People

Translate

site design / logo © 2022 Grokbase