I have this code, which I want should open the file(Output.csv) only if there are more than 0 rows returned by the SQL query. I tried using mysqli_num_rows() but wasn't helpful. here is my current code:
#!/usr/bin/perl -w
BEGIN {
$ENV{ORACLE_HOME}='/u01/app/oracle/product/11.1.0/';
}
use strict;
use DBI;
use utf8;
#use Text::CSV;
my $DB='database';
my $db_user='user';
my $password=`/usr/bin/pmo view password -u $db_user -t $DB`; chomp($password); my $db = DBI->connect( "dbi:Oracle:database", $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 * from my table T where T.last_updates=(SYSTDATE -2) ");
open my $fh, '>>', 'Output.csv' or die "Could not open file Output.csv: $!";
$sth->execute;
while (my @res = $sth->fetchrow_array) {
print $fh qq{$res[0]\t$res[1]\n};
}
close $fh;
print "If you see this, execute phase succeeded without a problem.\n";
END {
$db->disconnect if defined($db);
}