1
fetchrow_hashrefから別のカラムを取得するにはどうすればよいですか?perl - dbiコールで追加カラムを取得するのに役立ちます
たとえば、私の元のサブルーチンは1つの値を返しました。
sub get_val
{
undef $/;
open (my $FH, "< tst.sql") or die "error can't open this file $!";
my $sth= $dbh->prepare(<$FH>) ||
die ("Cannot connect to the database: ".$DBI::errstr."\n");
$sth->execute;
close $FH;
my $row = $sth->fetchrow_hashref;
$sth->finish;
return $row->{COL1};
print $row;
}
私は今、私はお返しに2つの値を取得し、COL2
COL1 COL2
------ -------
1 A
を取得したいよ、私はget_valで呼び出すのはここで、私のSQLを変更:
my $dbh = DBI->connect(
$abc{oracle_dbi_connect},
$abc{usr},
$abc{pw},
{AutoCommit => 0,RaiseError => 0, PrintError => 0}) || die ("Cannot connect to the database: ".$DBI::errstr."\n");
my $val = get_val();
$dbh->disconnect();
私はCOL2の結果を新しい$ val2に割り当てる必要があるでしょうか?
はあなたに感謝。今すぐ素晴らしい作品です:-) – jdamae