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

Dear Monks,

I am finally writting a DBI Perl script.
I want to call a stored proc. from my script ...
#!/usr/bin/perl -w use strict; use DBI; use Getopt::Std; use vars qw/ $opt_d $opt_u $opt_p /; my $db = 'SPROD'; my $user = 'SPROD'; my $pass = 'SPROD'; my $dbd = 'Oracle'; my $sql = 'exec RBC_test( :? );'; getopts ( "d:u:p:h" ); if ( $opt_d ) { $db = $opt_d; } if ( $opt_u ) { $user = $opt_u; } if ( $opt_p ) { $pass = $opt_p; } my $dbh = DBI->connect ( $db, $user, $pass, $dbd ); if( !$dbh ) { print "Cannot connect to database: $DBI::errstr\n"; die "Terminating\n"; } my $sth = $dbh->prepare( $sql ); #$sth->bind_param( ":p", 123 ); $sth->execute(321) or print "Error [" . $sth->errstr . "]\n"; my $rc = $dbh->disconnect(); print "Disconnected rc = $rc\n";
Here's the error message ...
Error [ORA-00900: invalid SQL statement (DBD ERROR: OCIStmtExecute)] Disconnected rc = 1
procedure RBC_test is very simple procedure that takes one
parameter and then just does a DBMS_OUTPUT.PUT_LINE( to_char(n) );
How am suppose to call stored procedures from a DBI script?

Thanks

Replies are listed 'Best First'.
Re: DBI/Oracle stored procedure newbee question
by metadatum (Scribe) on Aug 22, 2002 at 18:30 UTC
    exec is a SQL*Plus command. See http://search.cpan.org/author/TIMB/DBD-Oracle-1.12/Oracle.pm for how to call a stored proc, i.e.
    $csr = $db->prepare(q{ BEGIN PLSQL_EXAMPLE.PROC_NP; END; }); $csr->execute;
Re: DBI/Oracle stored procedure newbee question
by DamnDirtyApe (Curate) on Aug 22, 2002 at 18:30 UTC

    I believe you have to treat it as a PL/SQL block, and say something more like:

    my $sql = 'BEGIN exec RBC_test( :? ); END;';

    Strictly speaking, calling stored procedures is not supported by the DBI, though some drivers support it. Take a look at the DBD::Oracle documentation for more info.


    _______________
    DamnDirtyApe
    Those who know that they are profound strive for clarity. Those who
    would like to seem profound to the crowd strive for obscurity.
                --Friedrich Nietzsche