#c:\perl\bin use DBI; use strict; use warnings; #extablishing connection to database my $dbname = "oracle11gr2"; my $dbuser = "scott"; my $dbpass = "tiger"; my $dbh = DBI->connect("dbi:Oracle:$dbname", $dbuser, $dbpass) || die "Unable to connect to $dbname: $DBI::errstr\n"; #truncating table for fresh loading my $trun = "truncate table emp_test "; my $trsth = $dbh->prepare($trun); $trsth->execute() ; #declaring required variables. my $no=""; my $abc=""; my $ins =""; my $inssth=""; my $totalrecords=0; my $success=0; my $fail=0; #looping through all rows of data and insert into table my $data_file="./examples/names.txt"; open(NAMES, $data_file) || die("Could not open file!"); foreach my $line () { $totalrecords +=1; chomp($line); ($no,$abc)=split(/\|/,$line); $ins = "insert into emp_test values( " . $no . ",'" . $abc . "')"; eval { $inssth =$dbh->prepare($ins); $inssth->execute(); }; } my $comm = "commit"; my $commit = $dbh->prepare($comm); $commit->execute() ; print "total Number of records in file is: " . $totalrecords . "\n"; print "total Number of successfull loaded records is: " . $success . "\n"; print "total Number of failed records from file is: " . $fail , "\n"; #commiting at end of program