I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2009-12-17 20:07:43-08 by mcdave
Does DBD::Oracle really support binding arrays?
I tried to pass an array to a stored procedure, as mentioned in the DBD::Oracle documentation, section "SYS.DBMS_SQL datatypes", but got the message "bind_param_inout needs a reference to a scalar value" Thanks for any help. The whole output of my script is
DBI version 1.609 DBD::Oracle version 1.23 Checking ORA_VARCHAR2_TABLE example bind_param_inout needs a reference to a scalar value at ora_arrays.pl line 39. Checking ORA_NUMBER_TABLE example bind_param_inout needs a reference to a scalar value at ora_arrays.pl line 73.
and the script itself is
#!/usr/bin/perl -w use strict ; use Data::Dumper ; use DBI ; use DBD::Oracle qw(:ora_types) ; my $dbh = DBI->connect( "DBI:Oracle:$ENV{'ORACLE_SID'}", $ENV{'ORA_USER'},$ENV{'ORA_PASS'}, { RaiseError => 1, PrintError => 0, AutoCommit => 0, } ) or die "Cannot connect to Oracle: $DBI::errstr" ; print "DBI version $DBI::VERSION\n" ; print "DBD::Oracle version $DBD::Oracle::VERSION\n" ; eval { print "Checking ORA_VARCHAR2_TABLE example\n" ; 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 ); my @arr=( "abc" ); my $cc ; $sth->bind_param_inout(":mytable", \@arr, 10, { ora_type => ORA_VARCHAR2_TABLE, ora_maxarray_numentries => 100 } ); $sth->bind_param_inout(":cc", \$cc, 100 ); $sth->execute(); print "Result: cc=",$cc,"\n", "\tarr=",Data::Dumper::Dumper(\@arr),"\n"; } ; warn $@ if $@ ; eval { print "Checking ORA_NUMBER_TABLE example\n" ; my $statement=' DECLARE tbl SYS.DBMS_SQL.NUMBER_TABLE; BEGIN tbl := :mytable; :cc := tbl(2); tbl(4) := -1; tbl(5) := -2; :mytable := tbl; END; '; my $sth=$dbh->prepare( $statement ); if( ! defined($sth) ){ die "Prepare error: ",$dbh->errstr,"\n"; } my @arr=( 1,"2E0","3.5" ); # note, that ora_internal_type defaults to SQLT_FLT for ORA_NUMBER_TABLE . if( not $sth->bind_param_inout(":mytable", \@arr, 10, { ora_type => ORA_NUMBER_TABLE, ora_maxarray_numentries => (scalar(@arr)+2), ora_internal_type => SQLT_FLT } ) ){ die "bind :mytable error: ",$dbh->errstr,"\n"; } my $cc=undef; 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"; } ; warn $@ if $@ ;
Direct Responses: 11977 | Write a response
Posted on 2009-12-17 21:18:16-08 by mcdave in response to 11976
Re: Does DBD::Oracle really support binding arrays?
...and then I subscribe to perl.dbd.oracle.changes and see r13455, in which the "\@arr" is changed to "\\@arr" in the documentation and it all works great! So DBD::Oracle actually does support binding arrays after all.
Direct Responses: Write a response