Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Basic oraperl array question

Re: Basic oraperl array question

From: John D Groenveld <groenvel_at_cse.psu.edu>
Date: 3 Jun 1999 15:06:24 -0400
Message-ID: <7j6jng$fik$1@hubsch.cse.psu.edu>


In article <KTx53.667$m4.3117_at_nntp1>,
Jared Hecker <jhecker_at_iago.nac.net> wrote:
>Nothing in the Oraperl docs refers to this and I feel like I am writing
>way too many cursors and fetches to do something like this.
perldoc Oraperl
 ora_fetch

       Used in an array context, the value returned is an array
       containing the data, one element per field. Note that this
       will not work as expected:

If you switch from the emulation module to DBI, you can access those values in a multitude of ways. See perldoc DBI

#!/usr/bin/perl -w
use strict;
use DBI;
my $dbh = DBI->connect("dbi:Oracle:", "scott", "tiger", {RaiseError=>1}); my $sth = $dbh->prepare("SELECT ename, empno FROM emp"); $sth->execute();
#
my ($ename, $empno);
$sth->bind_columns(undef, \($ename, $empno)); while ($sth->fetchrow-arrayref) {

    print $ename, $empno;
}

## or
#my @row;
#while (@row = $sth->fetchrow_array) {
#    print $row[0], $row[1];
#}
## or
#my $row_ref;
#while ($row_ref = $sth->fetchrow_hashref) {
#    print $row_ref->{"ENAME"}, $row_ref->{"EMPNO"};
#}

$sth->finish;
$dbh->disconnect;

>If it is convenient, e-mail will reach me faster.
While faster and more convenient for you, email does nothing to help save the world by sharing our answers and allowing them to be archived. John
groenveld_at_acm.org Received on Thu Jun 03 1999 - 14:06:24 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US