in reply to Re^3: Getting stored procedure results from Oracle using a Perl
in thread Getting stored procedure results from Oracle using Perl
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; /
#!/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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Getting stored procedure results from Oracle using a Perl
by marto (Cardinal) on Jul 27, 2005 at 10:33 UTC |