#! /usr/bin/perl
use DBI;
use strict;
use Data::Dumper;
my $dbh = DBI->connect("DBI:DB2:xxx",'xxx','xxx',{ RaiseError => 0, AutoCommit => 1 })
or die ("Could not connect to database :".DBI->errstr);
my %hash =
(
'2017-01-01 00:00:00' => '2017-01-31 00:00:00',
'2017-02-01 00:00:00' => '2017-02-28 00:00:00',
'2017-03-01 00:00:00' => '2017-03-31 00:00:00',
'2017-04-01 00:00:00' => '2017-04-30 00:00:00',
'2017-05-01 00:00:00' => '2017-05-31 00:00:00',
'2017-06-01 00:00:00' => '2017-06-30 00:00:00',
'2017-07-01 00:00:00' => '2017-07-31 00:00:00',
'2017-08-01 00:00:00' => '2017-08-31 00:00:00',
'2017-09-01 00:00:00' => '2017-09-30 00:00:00'
);
#open(my $fh , "+>/var/www/bin/filesample.txt");
foreach my $key(sort keys %hash) {
chomp($key);
#my $sql = "select distinct FID_CUST from session where DAT_END between ? and ?";
my $sql = "select distinct FID_CUST from session where DAT_END between TIMESTAMP(?) and TIMESTAMP(?)";
print "\$sql = $sql\n";
my $sth = $dbh->prepare($sql);
$sth->execute($key,$hash{$key}) or die "Couldn't execute statement: $DBI::errstr";
print "sth: $sth\n";
while (my $arr = $sth->fetchrow_arrayref()){
print "in while\n";
print "@$arr\n";
}
$sth->finish();
}
#close FH;
$dbh->disconnect;
在這裏,我不能得到什麼是錯的代碼,因爲控制不會去循環。請建議可以做些什麼。我正在使用DB2數據庫。我沒有收到任何錯誤,但它不會顯示任何輸出。我用佔位符也使用了TIMESTAMP,但它顯示了一些模糊性錯誤。無法解析代碼中的日期和流程是不會去while循環
「出一些模糊的錯誤。」 ??? –
缺少'使用警告;'。 – melpomene
DBD :: DB2 :: db準備失敗:[IBM] [CLI驅動程序] [DB2/AIX64] SQL0245N例程「TIMESTAMP」的調用不明確。位置「1」的論點並不適合。 SQLSTATE = 428F5 DBD :: DB2 :: st執行失敗:[IBM] [CLI驅動程序] [DB2/AIX64] SQL0245N例程「TIMESTAMP」的調用不明確。位置「1」的論點並不適合。SQLSTATE = 428F5 無法運行:[IBM] [CLI Driver] [DB2/AIX64] SQL0245N例程「TIMESTAMP」的調用不明確。位置「1」的論點並不適合。 SQLSTATE = 428F5 –