Reputation: 347
How to execute sybase stored procedure** "dbo.xyz" in perl script?
my $procedure = "call dbo.GetAllBooks";
my $ExecProc = $dbh -> prepare($procedure) or die "Unable to prepare '$procedure'";
$ExecProc -> execute();
while (@data = $ExecProc->fetchrow_array)
{
open (FH, ">>Output.csv") or die "Could not open file Output.csv: $!";
print FH "@data $csv_record .\n";;
close (Output.csv);
}
Upvotes: 1
Views: 6953
Reputation: 4737
If you're using DBI
and DBD::Sybase
, stored procedures are handled exactly the same way as executing any other SQL statement. There is one difference in that it will also return an extra result set for the return status. You can check the value of $sth->{ syb_result_type }
to see if it is CS_STATUS_RESULT
while calling the fetch*
methods.
DBD::Sybase
is a bit weird compared to other database drivers however. Some things may be just too difficult given the DB-Library that Sybase provides for developers so I personally don't blame the author for implementing the driver this way. DBD::Sybase
is still done really well though.
You should definitely take some time to read the stored procedure section of the documentation in CPAN since it describe what it does and does not do. Actually, grab a cup of coffee and read all of it. I've done a good amount of work using DBD::Sybase
and it has really helped me out.
Calling Stored Procedures in DBD::Sybase
Upvotes: 1
Reputation: 7689
Exactly like this:
my $sql = qq{ BEGIN SCHEMA_NAME.STORED_PROC_NAME(); END;};
my $sth = $dbh->prepare($sql) || die $sth->$DBI::errstr;
$sth->execute || die $sth->errstr; }
Upvotes: 1