aroc725 has asked for the wisdom of the Perl Monks concerning the following question:

I'm using DBI.pm and I need to call a Sybase stored procedure that has an output parameter. Does anyone know the right syntax for doing this?
  • Comment on calling a stored procedure using DBI.pm

Replies are listed 'Best First'.
Re: calling a stored procedure using DBI.pm
by reyjrar (Hermit) on Apr 12, 2006 at 19:50 UTC
    Did you:
    ... my $sth = $dbh->prepare($StoredProcedureSQL); if(!$sth->execute(@args)) { print "Met with error: ", $sth->errstr, "\n"; # exit / die / croak / return / next / last } while ( my $row = $sth->fetchrow_arrayref ) { ... } ...
    Cuz I've done that a million times on Sybase without any problems. Also, check $sth->rows.
    -brad..
      Thanks to everyone who took the time to respond.

      I think the documentation may be slightly off. Here's what appears in the documentation I was referred to:
      ...
      $sth = $dbh->prepare("declare \@id_value int, \@id_name exec my_proc @name = 'a string', @number = 1234, @id = @id_value OUTPUT, @out_name = @id_name OUTPUT");
      ...

      Question - isn't the backslash (\) character needed in front of every '@' character within the string containing the stored procedure call ?
        isn't the backslash (\) character needed in front of every '@' character within the string...

        Yes it is. I think under older perls, it may have been just a warning, but now you definitely need the backslash to not try to interpolate arrays in a double quoted string (and is a fatal error under use strict if you try to interpolate a non-existant array).

        Yes, or you could use a single-quoted string.
        You are correct - the backslashes are missing, a typo in the docs which I'll correct.

        Michael

Re: calling a stored procedure using DBI.pm
by runrig (Abbot) on Apr 12, 2006 at 18:37 UTC
      Thanks, but it doesn't look like the call to 'fetch' is getting anything back from the stored procedure call. Weird.