Avatar of chainfear
chainfear

asked on 

Dump Oracle database to CSV using perl DBI

Hi Experts,

I am new to perl. As per title, below is my codes:
#!/usr/bin/perl

use strict;
use warnings;
use DBI;


my $dbh = DBI->connect('dbi:Oracle:host=x.x.x.x;sid=xxxx;port=1521',
               'user', 'pass', { RaiseError => 1, AutoCommit => 0 });

open(my $outputFile, '>', 'file.tsv');
my $sth = $dbh->prepare('SELECT * FROM SCHEMA.TABLE');
$sth->execute;
my $row;
while ($row = $sth->fetchrow_arrayref)
{
  print $outputFile join("|", @$row) . "\n";
}

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

Open in new window


I am getting this error:
Use of uninitialized value in join or string at ./q6.pl line 17, which is this line:
print $outputFile join("|", @$row) . "\n";

Open in new window


Any clue?

Thanks!
PerlOracle Database

Avatar of undefined
Last Comment
wilcoxon

8/22/2022 - Mon