Here is the snippet that i used to execute a query.
my $_connectOracle = sub {
my $oracle_server = $_[0];
my $sid = $_[1];
my $user_id = $_[2];
my $password = $_[3];
my $db_type = "Oracle";
my $dbh;
eval
{
$dbh = DBI->connect ("dbi:$db_type:host=$oracle_server;sid=$si
+d",
$user_id,
$password,
{
PrintError => 0,
RaiseError => 1
}
);
};
if ($@) # check if the connection has made
{
$error_no = $DBI::err;
$error_msg = $DBI::errstr;
}
return $dbh;
};
sub executeQuery () {
my $query_type = $_[1];
my $query_desc = $_[2];
my $oracle_server = $_[3];
my $sid = $_[4];
my $user_id = $_[5];
my $password = $_[6];
my $dbh;
my $sth; # Statement handle
my $output_values;
my @output_values;
# Get the database handle with the given input parameter.
$error_no = "";
$dbh = &$_connectOracle($oracle_server, $sid, $user_id, $password)
+;
if ( ! $error_no ) {
eval
{
if ($query_type eq "S") {
$sth = $dbh->prepare($query_desc);
$sth->execute();
while ($output_values = $sth->fetchrow_hashref)
{
push (@output_values, $output_values);
}
}
else {
$dbh->do("$query_desc");
}
$dbh->disconnect();
};
if ($@)
{
$error_no = $DBI::err;
$error_msg = $DBI::errstr;
}
return @output_values;
}
else {
print "\nCannot connect to database\n";
print "because $error_no\n";
}
}
what am doing here is when i call the execute sub-routine i build a string that will have the file contents (to create a proc. which is 1100 lines ). When i call this function am getting the oracle error 24344 which doesnot convey anything other than "the procedure created with compilation errors". But when i run the same procedure in the sql plus using @ am able to create the proc. without any error that ensures that the procedure is correct syntactially. Hope am clear.
Edit by castaway - added code tags |