in reply to Getting stored procedure results from Oracle using Perl

Hi,

What have you got so far? You have not posted any Perl code.
You should have a look at How do I post a question effectively? then read Before asking a database related question ....

Hope this helps

Martin
  • Comment on Re: Getting stored procedure results from Oracle using a Perl

Replies are listed 'Best First'.
Re^2: Getting stored procedure results from Oracle using a Perl
by geraltan (Initiate) on Jul 27, 2005 at 09:47 UTC
    Thanks Martin. I should rephrase my question, if I created a stored procedure in Oracle using the above codes, how do I call it and have results returned in perl? Thanks!
      Hi geraltan,

      Do you have any experience of Perl?
      Are you familiar with Database communication using Perl?
      If the answer is no, I would suggest reading some of this sites fantastic Tutorials.
      You want to connect to Oracle using DBI.
      You will also need DBD::Oracle if you do not already have it.

      There are plenty of examples of retrieving values from stored procedures. This off site reference is one I looked at a while back that contains an easy to follow example.

      Happy reading.

      Martin
        I wrote the following in perl but it is not running. Anything wrong with it?
        Stored Procedure created in Oracle
        CREATE OR REPLACE procedure select_pm (n_QC_DEPL_S1 in NUMBER) is n_PM_DEPL_S1 NUMBER(3); begin DBMS_OUTPUT.PUT_LINE (n_QC_DEPL_S1); select PM_DEPL_S1 into n_PM_DEPL_S1 from EIP_SR_SECT_PERF where QC_DEPL_S1 = n_QC_DEPL_S1; DBMS_OUTPUT.PUT_LINE (n_QC_DEPL_S1); end select_pm; /

        Perl program to get the results
        #!/usr/bin/perl use DBI; use strict; require 'insert_db_dev.pl'; require 'database_dev.pl'; require 'general_functions.pl'; open(LOGFILE, '> ..\\logs\\geraltan_stored_proc.txt') or die "Can't cr +eate logfile!\n"; get_results(); sub get_results() { printlog("Connecting to database."); #my $dbh=connect_db(get_user_passwd()); my $dbh = DBI->connect('dbi:Oracle:host=ABC;sid=ABC123;port=1521', + 'abc','abc'); printlog("Connected."); my $rv; eval { my $func = $dbh->prepare(q{ BEGIN :cursor := select_pm( parame +ter1_in => :parameter1); END; }); $func->bind_param(":parameter1", '2'); $func->bind_param_inout(":cursor ", \$rv, 0, { ora_type => ORA +_RSET}); $func->execute; $func->finish; $dbh->commit; } if( $@ ) { warn "Execution of stored procedure failed: $DBI::errstr\n"; $dbh->rollback; } printlog("Execution of stored procedure returned $rv\n"); while(my $hashRef = $rv->fetchrow_hashref) { foreach(keys %$hashRef) { printlog("$_ is $hashRef->{$_}\n"); } } $rv->finish; printlog("Disconnecting from database..."); $dbh->disconnect; printlog("Disconnected."); } sub printlog($) { my $msg=shift; print $msg,"\n"; print LOGFILE $msg,"\n"; } close LOGFILE;