【问题标题】:Bulk Insert into Oracle XMLTYPE Using Perl使用 Perl 批量插入 Oracle XMLTYPE
【发布时间】:2015-12-22 09:59:05
【问题描述】:

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

有人可以从 Perl 批量插入 XMLTYPE 吗?

这里是sn-ps的两个代码。一个用于 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"); }

【问题讨论】:

  • 您使用的是哪个版本的 DBD::Oracle?
  • 您尝试'INSERT INTO ' . $table . ' (XMLCONTENT) VALUES (XMLTYPE(?))'INSERT INTO ' . $table . ' (XMLCONTENT) VALUES (XMLPARSE(CONTENT ? WELLFORMED))' 然后将您的XML 作为CLOB 发送?
  • @collapsar 1.74 版
  • @WernfriedDomscheit 我收到来自 Oracle 的错误 ora01461 can't bind a LONG only for insert into a LONG column。我想我肯定需要类型减速
  • $sth->bind_param_array(1,\@xmldocuments,{ ora_type => ORA_CLOB }) 是否也出现同样的错误?

标签: oracle perl xmltype dbd


【解决方案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"); 
}

【讨论】:

    猜你喜欢
    • 2015-02-08
    • 1970-01-01
    • 1970-01-01
    • 2012-01-17
    • 2010-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多