0

perlのモジュールを使用して、DBD::Oraclexml コンテンツを oracle 11 g インスタンスに挿入しています。サンプル セットにいくつかのドキュメントを挿入しているときに、モジュールが を返すため、スクリプトは失敗しますUnsupported named object type for bind parameter。このエラーを処理し、ループの反復を続行したいと思います。

以下は私のコードです、

use strict;
use warnings;
use DBI;
use DBD::Oracle qw(:ora_session_modes);
use DBD::Oracle qw(:ora_types);

die("USAGE: $0 <input_directory>") unless ($#ARGV == 0);
my $directory=$ARGV[0];

my $dbh = DBI->connect('dbi:Oraclle:dbname',"username", "pass");
my $SQL;



opendir(IMD, $directory) || die ("Cannot open directory");
my @listOfFiles= readdir(IMD);
closedir(IMD);

my $xmltype_string;
my $xml;
my $i = 1; 
foreach my $file(@listOfFiles)
{
    unless($file eq '.' or $file eq '..')
    {
        print "inserting File no. $i \t $file .... \n";

        {
                local $/=undef;
                open (FILE , "<" , "$directory/$file" );
                $xml=<FILE>;
                close (FILE);
        }
        $SQL="insert into sampleTable values ( :ind, :xml)";
        my $sth =$dbh-> prepare($SQL);
        $sth->bind_param(":xml" , $xml , { ora_type => ORA_XMLTYPE});
        $sth->bind_param(":ind" , $i);
        $sth-> execute();


        $i++;
    }
}

バインド パラメータでエラーが発生しています。

4

1 に答える 1

4

エラー処理は通常、Try::Tinyモジュールを介して行われます。

use Try::Tiny;

try {
    something_that_could_die();
}
catch {
    handle_error($_);
}
finally {
    do_something_either_way();
}; # ← trailing semicolon not optional.

catchとはどちらfinallyもオプションです。

于 2014-04-16T09:15:44.713 に答える