I have to create a table using the create table statement and then insert values into the table using the insert statement.
The third query would be the sql/xml query against the table i have created.
I need to write a perl script which will connect to the database and execute these 3 queries and generate an xml output file
from the sql xml query.
My code is as follows:-
my $outputFile = shift(@ARGV);
my $env = shift(@ARGV);
if ($env eq "PROD")
{
$schema_name = "PROD";
$SID = "PRODUCTION";
$USERNAME = "Puser";
$PASSWORD = "****";
}
if ($env eq "TEST")
{
$SID = "TEST";
$schema_name = "QA";
$USERNAME = "QAUSER";
$PASSWORD = "****";
}
my $filename = $outputFile;
my $sqlcode1 = qq{create table query};
my $sqlcode2 = qq{insert table query};
my $sqlcode3 = qq{sql/xml table query};
open (FILE, ">" . $filename) or die "Cannot create output file: $!\n:";
my $dbh = DBI->connect($SID,$USERNAM
E,$PASSWOR
D,"Oracle"
)
or die "Couldn't connect to database: ";
my $sth1 = $dbh->prepare($sqlcode1)
or die "Couldn't prepare statement: ";
$sth1->execute()or die $sth1->errstr;
my $sth2 = $dbh->prepare($sqlcode2)
or die "Couldn't prepare statement: ";
$sth2->execute()or die $sth2->errstr;
my $sth3 = $dbh->prepare($sqlcode3)
or die $dbh->errstr;
$sth3->execute()or die $sth3->errstr;
my @ary = $sth3->fetchrow_array;
print $sth3->rows;
print $#ary;
print FILE $ary[0];
close (FILE);
$dbh->disconnect();
it comes up with the below warning and the file created is empty.Please help.
1
DBI::db=HASH(0x1b8ff18)->d
isconnect invalidates 1 active statement handle (eithe
r destroy statement handles or call finish on them before disconnecting)
-1
Start Free Trial