#!/usr/bin/perl

use strict;
use warnings;

BEGIN{
	use lib 'blib/lib';
	use lib 'blib/arch';
	use lib 'blib/arch/auto';
	use lib 'lib';
	use lib '.';
};

use Data::Dumper;
use DBI;


use DBD::Oracle qw(:ora_types);

my $dsn = 'dbi:Oracle:mydb';
my $user = 'myuser';
my $password = 'mypw';

my $dbh = DBI->connect($dsn, $user, $password,
			{ RaiseError => 0, AutoCommit => 0 });

my $statement='
DECLARE
	tbl	SYS.DBMS_SQL.VARCHAR2_TABLE;
BEGIN
	tbl := :mytable;
	:cc := tbl.count();
	tbl(1) := \'def\';
	tbl(2) := \'ijk\';
	:mytable := tbl;
END;
';

my $sth=$dbh->prepare( $statement );

if( ! defined($sth) ){
	die "Prapare error: ",$dbh->errstr,"\n";
}

my @arr=( "abc" );

if( not $sth->bind_param_inout(":mytable", \@arr1, 10, { TYPE => DBD::Oracle::ORA_VARCHAR2, ora_maxarray_numentries => 100 } ) ){
	die "bind :mytable error: ",$dbh->errstr,"\n";
}
my $cc;
if( not $sth->bind_param_inout(":cc", \$cc, 100 ) ){
	die "bind :cc error: ",$dbh->errstr,"\n";
}

if( not $sth->execute() ){
	die "Execute failed: ",$dbh->errstr,"\n";
}
print	"Result: cc=",$cc,"\n",
	"\tarr=",Data::Dumper::Dumper(\@arr),"\n";

$dbh->disconnect();
