rb_rb has asked for the wisdom of the Perl Monks concerning the following question:

Hallo, I tried a select - statement in an oracle database via a DBI connection. I included DBI in my perl script. The connect worked correctly as well as the 'prepare' - method. Then the ececute method failed with following error message: 'Can't locate object method "execute" via package "DBI::db" at ...' (an insert statement via the 'do' method worked) And this is the code:
use warnings; use DBI; my($dbh, $sql, $res, @result, $kennz, $dbiServiceName); $dbiServiceName = "DBI:Oracle:prod"; $dbh = DBI->connect($dbiServiceName,"ibis01","ibis01"); if (defined($dbh)) { $sql = "select * from test"; $res = $dbh->prepare($sql); $res = $dbh->execute(); @result = $dbh->fetchrow_array(); $dbh->disconnect(); }
What can be the reason? R.B.

Replies are listed 'Best First'.
Re: Execute in DBI fails
by Joost (Canon) on May 19, 2005 at 14:49 UTC
Re: Execute in DBI fails
by the_0ne (Pilgrim) on May 19, 2005 at 18:11 UTC
    You can also cut down on some code by using the DBI methods...

    @row_ary = $dbh->selectrow_array($statement); $ary_ref = $dbh->selectrow_arrayref($statement); $hash_ref = $dbh->selectrow_hashref($statement);
    No need for prepare and execute then.

    Good luck!
Re: Execute in DBI fails
by holli (Abbot) on May 19, 2005 at 15:13 UTC
    Welcome to the monastery Frau Braun. As I told you on the phone it won't take more than 3 minutes to get an answer. This is a great place! Thanks Joost for proving me correct. :-)

    If you plan to lurk around here more often, be sure to read the monastery guidelines. Have a look at my homenode which holds a collection of nodes that are interesting for site newbies.

    Happy perling!


    holli, /regexed monk/