it appears that you called '$dbh->disconnect' alittle prematurely. move
this method to the end of your code block and all should work
<ss>
"TIBA, LIVIA" wrote:
> Hi,
> Could someone help me with this code?!
>
> ##########################
> # Read a CSV file with "," as the separator, as exported by
> # MS Excel.
> ##########################
> require DBI;
> my $dbh = DBI->connect("DBI:CSV:");
> $dbh->{'csv_tables'}->{'employees'} = {
> 'eol' => "\n",
> 'sep_char' => ",",
> 'quote_char' => undef,
> 'escape_char' => undef,
> 'file' => './employees',
> 'col_names' => ["lname", "fname", "uid", "pein", "email", "phone",
> "cellphone"]
> };
> $dbh->do("DROP TABLE employees");
> $sth = $dbh->prepare("CREATE TABLE employees (lname CHAR(10), fname
> CHAR(10),
> uid CHAR(10), pein CHAR(10), email CHAR(35), phone
> CHAR(15),
> cellphone CHAR(15))")
> or die "Cannot prepare: " . $dbh->errstr();
> $sth->execute() or die "Cannot execute: " . $sth->errstr();
> $sth->finish();
> $dbh->disconnect();
>
> $sth = $dbh->prepare("INSERT INTO employees
> (lname,fname,uid,pein,email,phone,cellphone)
>
> VALUES (?,?,?,?,?,?,?)") || die $dbh->errstr;
> while(<CSV>) {
> chop;
> my ($lname, $fname, $uid, $pein, $email, $phone, $cellphone) = split
> /,/;
> $sth->execute( $lname, $fname, $uid, $pein, $email, $phone,
> $cellphone ) || die
>
> $dbh->errstr;
> }
>
> $sth = $dbh->prepare("SELECT * FROM employees");
> $sth->execute();
> while (my $row = $sth->fetchrow_hashref) {
> print("Lname = ", $row->{'lname'},
> ", Fname = ", $row->{'fname'},
> ", Userid = ", $row->{'uid'},
> ", PEIN = ", $row->{'pein'},
> ", Email = ", $row->{'email'},
> ", OfficePhone = ", $row->{'phone'},
> ", Cellphone = ", $row->{'cellphone'},"\n");
> }
> $sth->finish();
> ----------------------------------
>
> It creates table 'employees', but can't do insert in this table. What is
> wrong?!
> If this table is create and populate will be recognize by Oracle, SQL
> as SQL table, or I have to use DBD::Oracle?
> Thanks for any help!
>
> Livia
--
Steve Sanden
Programmer/Analyst
PeopleSoft Technical Team
Whole Foods Market, Inc.
tel. 512.477.5566 x.1262
fax. 512.344.6693
"It's kinda fun to do the impossible" -- Walt Disney
#include <std_disclaimer.h>