使用Perl

时间:2015-12-22 09:59:06

标签: oracle perl xmltype dbd

我使用Perl DBD :: Oracle尝试将XML字符串数组批量插入Oracle XMLTYPE列。如果我批量插入CLOB,但是当我尝试通过Strawberry Perl插入XMLTYPE列时崩溃,我可以使它工作。

是否有人能够从Perl批量插入XMLTYPE?

以下是两个代码段。一个用于CLOB,第二个用于XMLTYPE ....

sub save_xml {
$log->write("Inserting XML messages into table:$table, in $mode: mode"); my @status; my $sql='INSERT INTO ' . $table . ' (XMLCONTENT) VALUES (?)'; my $sth = $dbh->prepare_cached($sql) || die "Cannot prepare statement: $DBI::errstr"; $sth->bind_param_array(1,\@xmldocuments) || die "Cannot bind parameter array: $DBI::errstr"; $sth->execute_array({ArrayTupleStatus=>\@status}) || die "Cannot bulk insert into table: $table: $DBI::errstr"; $log->write("Inserted $status rows into table: $table"); }

sub save_xml {
$log->write("Inserting XML messages into table:$table, in $mode: mode"); my @status; my $sql='INSERT INTO ' . $table . ' (XMLCONTENT) VALUES (?)'; my $sth = $dbh->prepare_cached($sql) || die "Cannot prepare statement: $DBI::errstr"; $sth->bind_param_array(1,\@xmldocuments,{ ora_type => ORA_XMLTYPE }) || die "Cannot bind parameter array: $DBI::errstr"; $sth->execute_array({ArrayTupleStatus=>\@status}) || die "Cannot bulk insert into table: $table: $DBI::errstr"; $log->write("Inserted $status rows into table: $table"); }

1 个答案:

答案 0 :(得分:1)

我无法让批量绑定与二进制XMLTYPE一起使用。但是,使用以下代码逐行处理可满足我的要求:

sub save_xml{ 
   my ($xml) = @_; 
   $log->write("Inserting XML message into table:$table, in $mode mode"); 
   my $sql='INSERT INTO ' . $table . ' (XMLCONTENT) VALUES (:xml)'; 
   my $sth = $dbh->prepare_cached($sql); 
   if ( $mode eq "BINARY" ) { 
       $sth-> bind_param(":xml", $xml, { ora_type => ORA_XMLTYPE }); 
   } else { 
       $sth-> bind_param(":xml", $xml); 
   } 
   $sth->execute() || die "Error whilst inserting into table: $table: $DBI::errstr"; 
   $log->write("Insert into table:$table successful"); 
}