#!/usr/local/bin/perl -w
use strict;

use DBI qw(:sql_types);				# Perl DBI Database Access module
use DBD::Oracle qw(:ora_types);		# Perl Oracle access module

# Database access variables
my $dbh;				# Database handle
my $sth;				# Statement handle
my $csr;				# Cursor reference
my @row;				# Returned data row

### DATABASE CONNECTIVITY PARAMETERS
my $OraInst = 'dbi:Oracle:DBA8';
my $UserName = 'c828764';
my $Password = '*********';
my %Options = (RaiseError=>1, AutoCommit=>0);

my $InParam= $ARGV[0];

my $ErrCode;

DBI->trace(5);

$dbh = DBI->connect( $OraInst, $UserName, $Password, \%Options)
		|| die "Database connection can't be made: ".$DBI::errstr."\n";

$sth = $dbh->prepare('BEGIN :1 := BUG_PACKAGE.BUG_FUNCTION(:2,:3); END;')
		|| die "Cannot prepare ".$DBI::errstr."\n";

$sth->bind_param_inout(1, \$ErrCode, 0)
		|| die "Cannot bind the OUT parameter ".$DBI::errstr."\n";

$sth->bind_param(2, $InParam)
		|| die "Cannot bind the IN parameter ".$DBI::errstr."\n";

$sth->bind_param_inout(3, \$csr, 0, { ora_type => ORA_RSET })
		|| die "Cannot bind the CURSOR parameter ".$DBI::errstr."\n";

$sth->execute()
		|| die "Cannot execute: ".$DBI::errstr."\n";

print (":1 = $ErrCode, :2 = $InParam, :3 = $csr\n");

while(@row = $csr->fetchrow_array) {
	print (join(',', @row)."\n");
}

$sth->finish
	|| die "Cannot finish the execution: ".$DBI::errstr."\n";

$dbh->disconnect
	|| warn "Database disconnect failed: $DBI::errstr\n";

