在连接(。)或字符串中使用未初始化的值 - 在perl脚本中出错

时间:2014-03-13 06:27:55

标签: oracle perl csv

我正在尝试将下面给出的perl的输出写入CSV但是它给出了这个错误。有人可以帮忙:

!/usr/bin/perl -w

BEGIN {   $ENV{ORACLE_HOME}='/u01/app/oracle/product/11.1.0/'; } 
use strict;

use DBI; 
use utf8;

my $DB='pre14msv'; 
my $db_user='SWAPP_OWNER'; 
my $password=`/usr/bin/pmo view password -u $db_user -t $DB`;
chomp($password); 
my $db = DBI->connect( "dbi:Oracle:pre14msv", $db_user, $password )
        || die( $DBI::errstr . "\n" );

$db->{AutoCommit}    = 0;
$db->{RaiseError}    = 1;
$db->{ora_check_sql} = 0;
$db->{RowCacheSize}  = 16;


my $sth = $db->prepare("SELECT 
        q.enq_time,DBMS_LOB.substr(q.user_data.chat_event_text,100) FROM
        swapp_owner.aq\$CHAT_EVENT_QUEUE_table q");

open my $fh, '>>', 'Output.csv' or die "Could not open file Output.csv: $!"; 
print $fh qq{q.enq_time\tq.user_data.chat_event_text\n};

$sth->execute; 
while (my $res = $sth->fetchrow_hashref) {   
    print $fh qq{$res->{'q.enq_time'}\t$res->{'q.user_data.chat_event_text'}\n}; 
}
close $fh;


print "If you see this, execute phase succeeded without a problem.\n";

END {
    $db->disconnect if defined($db); 
}

1 个答案:

答案 0 :(得分:2)

您从表格中选择了两个字段,但它们都没有被命名为NameCompanyName

相反,为什么不尝试这个:

while (my @res = $sth->fetchrow_array) {
    print $fh qq{$res[0]\t$res[1]\n};
}
close $fh;