Search code examples
perlsybase

How to execute stored procedure in perl?


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);
     }

Solution

  • 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; }