in reply to Re: How to store the data fetched from the database in perl
in thread How to store the data fetched from the database in perl

I have used below code while fetching data from the sql but i got the output as below

$sth->execute ($lBOA_BLC_MASTER_ID) or die "Cannot execute: " . $sth-> +errstr(); %data = map { $_ => 1 } $sth->fetchrow();

Output

$VAR1 = 'ABC'; $VAR2 = 1;
thanks and regards,

Replies are listed 'Best First'.
Re^3: How to store the data fetched from the database in perl
by choroba (Cardinal) on Jun 11, 2013 at 06:51 UTC
    fetchrow fetches one row at a time. If you want to fetch all the rows, use fetchall_arrayref. See DBI.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^3: How to store the data fetched from the database in perl
by Neighbour (Friar) on Jun 11, 2013 at 06:53 UTC
    Try using my $hr_data = $dbh->selectall_hashref('SELECT DISTINCT EMP_NAME FROM EMPLOYEE', [ 'EMP_NAME' ]);
    This fetches all data in one go.
    You can then use say "ABC exists" if exists $hr_data->{ABC}; to check if an element is there.
Re^3: How to store the data fetched from the database in perl
by frozenwithjoy (Priest) on Jun 11, 2013 at 06:51 UTC

    I haven't used this module before, so am not totally familiar with this method, but does this work?

    my %data; while ( my $result = $sth->fetchrow() ) { $data{$result} = 1; }