How to select the rows from oracle table using perl?

Hi,

I am connecting to oracle database using perl.

I am able to connect but i am not able to get all the rows from the table.

Here is the code.

#!/usr/bin/perl
use DBI;
my $dbh=DBI->connect("DBI:Oracle:student","class","welcome") or die "Couldnot connect oracle Database";
$sth=$dbh->prepare("select * from dummy")or die "cannot prepare the selected statement";
$sth->execute() or die "cannot execute the statement";
print "entered\n";
my @row;
while (@row = $sth->fetchrow_array) {  # retrieve one row
    print join(", ", @row), "\n";
}

Here is the table structure in Oracle.

SQL> describe dummy;
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 NAME                                               VARCHAR2(10)

SQL> select * from dummy;

NAME
----------
aaa
eee

I am not able to get the output. The output should be:

aaa eee

How can i get the above output in perl?

Help is very much appreciated.

Regards

C:\>
C:\>type fetch.pl
#!perl -w
use strict;
use DBI;
my $dbh;
my $sth;
my $name;
my $namelist;
$dbh = DBI->connect("DBI:Oracle:student","class","welcome") or die $dbh->errstr;
$sth = $dbh->prepare("select name from dummy") or die $dbh->errstr;
$sth->execute() or die $dbh->errstr;
while ($name = $sth->fetchrow) {
$namelist .= " $name";
}
print $namelist;
$sth->finish();
$dbh->disconnect();
 
C:\>
C:\>perl fetch.pl
 aaa eee
C:\>
C:\>

tyler_durden