Avatar of itortu
itortu
Flag for United States of America

asked on 

insert using perl script and data file

I need to insert multiple records into an oracle table. i am trying to use perl to do this but i keep getting an error:



C:\inser_into_dcl>fix_dcl_values.pl
Processing line 1 => '2010      xSubject2       Environmental Awareness
1002    18-JUL-08 03.21.59.696000000 PM 07-DEC-08 02.39.09.165000000 PM ECRM_DEV

DBD::Oracle::st execute failed: ORA-00001: unique constraint (TESTDOCMGT.PK_DCL)
 violated (DBD ERROR: OCIStmtExecute) [for Statement "INSERT INTO DCL (DCLID, DC
LFIELD, DCLVALUE, DCLDESCRIPTION, DCLPARENTID, SCHCREATETIMESTAMP, SCHMODIFYTIME
STAMP, SCHSOURCEID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" with ParamValues: :p5='1002
', :p6='18-JUL-08 03.21.59.696000000 PM', :p3='Environmental Awareness', :p7='07
-DEC-08 02.39.09.165000000 PM', :p1='2010', :p8='ECRM_DEV', :p4='', :p2='xSubjec
t2'] at C:\inser_into_dcl\fix_dcl_values.pl line 23, <$FILE> line 1.
DBD::Oracle::st execute failed: ORA-00001: unique constraint (TESTDOCMGT.PK_DCL)
 violated (DBD ERROR: OCIStmtExecute) [for Statement "INSERT INTO DCL (DCLID, DC
LFIELD, DCLVALUE, DCLDESCRIPTION, DCLPARENTID, SCHCREATETIMESTAMP, SCHMODIFYTIME
STAMP, SCHSOURCEID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)" with ParamValues: :p5='1002
', :p6='18-JUL-08 03.21.59.696000000 PM', :p3='Environmental Awareness', :p7='07
-DEC-08 02.39.09.165000000 PM', :p1='2010', :p8='ECRM_DEV', :p4='', :p2='xSubjec
t2'] at C:\inser_into_dcl\fix_dcl_values.pl line 23, <$FILE> line 1.
'
#!/usr/bin/perl
 
use strict;
use warnings;
use DBI;
 
# dev
my $dbh = DBI->connect('dbi:Oracle:host=pppp.iii.com;sid=pppp;port=1521', 
               'testuser', 'kasjd', 
               { RaiseError => 1});
 
                       
my $sth = $dbh->prepare("INSERT INTO DCL (DCLID, DCLFIELD, DCLVALUE, DCLDESCRIPTION, DCLPARENTID, SCHCREATETIMESTAMP, SCHMODIFYTIMESTAMP, SCHSOURCEID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
 
my $csv_file = "insert_data.txt";
open( my $FILE, '<', $csv_file) or die "Cannot open file $!";
 
while ( <$FILE> ) {
 
		print "Processing line $. => '$_'";
    chomp;
    my ($DCLID, $DCLFIELD, $DCLVALUE, $DCLDESCRIPTION, $DCLPARENTID, $SCHCREATETIMESTAMP, $SCHMODIFYTIMESTAMP, $SCHSOURCEID) = split(/\t/, $_, 8);
    $sth->execute($DCLID, $DCLFIELD, $DCLVALUE, $DCLDESCRIPTION, $DCLPARENTID, $SCHCREATETIMESTAMP, $SCHMODIFYTIMESTAMP, $SCHSOURCEID);
}
$dbh->disconnect;
close $FILE;

Open in new window

insert-data.txt
Perl

Avatar of undefined
Last Comment
FishMonger

8/22/2022 - Mon