Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl/DBI and joins advice needed .... 1

Status
Not open for further replies.

rab54

Programmer
Jan 28, 2004
112
GB
Hi gurus -

just need a nudge in the right direction -

How do I deal with joins with dbi eg

SELECT t1.name,t2.address FROM t1,t2
WHERE t1.name = t2.name

When I assign like this
my $name = "$ref->{'name'}";

I get an empty string back ....

The sql is ok .....

Left my DBI book at home - doh !

cheers all

Rab

 
Hi,
Code:
#!/usr/bin/perl -w
    use DBI;
    # Connexion a Oracle
    my $dbh = DBI->connect('dbi:Oracle:alias',,'user','passwd',) || die "Database connection not made: $DBI::errstr";    
       $sql = qq{SELECT t1.name,t2.address                                         FROM t1,t2
WHERE t1.name = t2.name};

$sth=$dbh->prepare($sql) ;
$sth->execute;
$sth->bind_columns(\($name, $address)) ;
$sth->fetch();

This way, on each fetch, $name will recieve name value.

But if you are sure you
assign like this
my $name = "$ref->{'name'}";
Then selectrow_hashref($sql) may help you. I don't know the sintax though, except
Code:
$hash_ref = $dbh->selectrow_hashref($statement);
so probably your $ref->{'name'} is $hash_ref->{'name'}

HTH,
Zephan
 
Genius ! Thank you kind sir - have a star !

cheers

Rab
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top