Running Oracle Stored Procedures
Posted: Fri Oct 28, 2016 2:09 am
I am new to Oracle and have been tasked with executing a number of stored procedures that will return either a time stamp or a number, and then alert on them based on the thresholds.
I know how to execute MSSQL and MySQL SPs but it seems that Oracle isn't the same.
For database queries I use the CPAN DBI perl module which works fine.
I can run a basic query against an Oracle DB ok but not execute an SP.
The connection part of my code is:
#############################################
$dbh = DBI->connect("dbi:Oracle:host=$server;port=$port;sid=$db",$dbusername,$dbpassword, {RaiseError => 0, AutoCommit => 0}) || die;
$select = "EXEC DKURTULAY.NAGIOS_SMS_TABLE_CHECK.SMS_COUNT_PASTHOUR";
$sth = $dbh->prepare($select) || die "\$sth not created!\n";
$sth->execute();
@res = $sth->fetchrow_array();
$sth->finish();
$dbh->disconnect();
$res = $res[0];
print "$res\n";
##################################
And the error I get is:
##################################
DBD::Oracle::st execute failed: ORA-00900: invalid SQL statement (DBD ERROR: OCIStmtExecute) [for Statement "EXEC DKURTULAY.NAGIOS_SMS_TABLE_CHECK.SMS_COUNT_PASTHOUR"]
DBD::Oracle::st fetchrow_array failed: ERROR no statement executing (perhaps you need to call execute first) [for Statement "EXEC DKURTULAY.NAGIOS_SMS_TABLE_CHECK.SMS_COUNT_PASTHOUR"]
##################################
I would appreciate any help.
Thanks
Tony
I know how to execute MSSQL and MySQL SPs but it seems that Oracle isn't the same.
For database queries I use the CPAN DBI perl module which works fine.
I can run a basic query against an Oracle DB ok but not execute an SP.
The connection part of my code is:
#############################################
$dbh = DBI->connect("dbi:Oracle:host=$server;port=$port;sid=$db",$dbusername,$dbpassword, {RaiseError => 0, AutoCommit => 0}) || die;
$select = "EXEC DKURTULAY.NAGIOS_SMS_TABLE_CHECK.SMS_COUNT_PASTHOUR";
$sth = $dbh->prepare($select) || die "\$sth not created!\n";
$sth->execute();
@res = $sth->fetchrow_array();
$sth->finish();
$dbh->disconnect();
$res = $res[0];
print "$res\n";
##################################
And the error I get is:
##################################
DBD::Oracle::st execute failed: ORA-00900: invalid SQL statement (DBD ERROR: OCIStmtExecute) [for Statement "EXEC DKURTULAY.NAGIOS_SMS_TABLE_CHECK.SMS_COUNT_PASTHOUR"]
DBD::Oracle::st fetchrow_array failed: ERROR no statement executing (perhaps you need to call execute first) [for Statement "EXEC DKURTULAY.NAGIOS_SMS_TABLE_CHECK.SMS_COUNT_PASTHOUR"]
##################################
I would appreciate any help.
Thanks
Tony