in reply to save the result of sql query in csv file
This is a trvial solution. It won't handle commas in your data which may need to be wrapped in quotes or escapeduse DBI; use strict; my $dbh = DBI->connect('dbi:Oracle:dev', 'myUser', 'myPass') || die "Cannot connect to database\n", $DBI::Errstr; my $sth = $dbh->prepare("select * from emp"); $sth->execute || die "failed to execute:\n ", $DBI::Errstr; open (FH, ">c:/temp/out.csv") || die "Cannot open file\n"; while (my @row = $sth->fetchrow_array) { print FH join(', ', @row), "\n"; } close FH; $dbh->disconnect;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: save the result of sql query in csv file
by valdez (Monsignor) on Mar 24, 2004 at 15:39 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |