我的哈希值是以逗号分隔的字符串。我想使用这两个值来从数据库中获取数据,并使用它们插入到不同的表中。我该怎么办?
#!/usr/bin/perl
use strict;
use Getopt::Long;
use Data::Dumper ;
use DBI;
my $dbh_oracle = DBI->connect(
"dbi:Oracle:pro",
'user',
'change',
{AutoCommit => 0, RaiseError => 1, LongReadLen => 1000000}
) or die "Cant connect to oracle\n";
my $company = "select id from company where company_name = ?";
my $insert = "insert into CODE_DATA values(CODE_SEQ.nextval,?,?,?,?,?,?,?,sysdate)";
my $array_values = {
'Phase' => '',
'Code' => 'SQ',
'Year' => '1965 , 1967',
'Company' => 'ROFL , TOL',
'stem' => 'TRM , TRX, TRY',
'ID' => '1697794',
'BOX' => ''
};
if ( $array_values->{'Company'} ne '' ) {
my $sthgetCompany = $dbh_oracle->prepare($company)
or die 'Cannot prepare the statement'. $dbh_oracle->errstr;
$sthgetCompany->execute($arrar_values->{'Company'})
or die 'Cannot execute the statement'. $dbh_oracle->errstr;
# Since it has more than one value it dies. I need to take one value then another to get the ID.
my $company_id = $sthgetCompany->fetch()
or die 'Cannot fetch the results.'. $dbh_oracle->errstr;
}
else {
}
答案 0 :(得分:0)
您需要使用bind_param和prepare方法。例如:
my $sthgetCompany = $dbh_oracle->prepare($company)
or die 'Cannot prepare the statement'. $dbh_oracle->errstr;
$sthgetCompany->bind_param(1,$company_name_value);
$sthgetCompany->execute;