Front page | perl.beginners |
Postings from May 2002
RE: select from oracle and write to file
Thread Previous
|
Thread Next
From:
Shah, Urmil
Date:
May 1, 2002 07:36
Subject:
RE: select from oracle and write to file
Message ID:
87EA450621E2D211B6EE0000F8CD2957109B3BE0@dlee07.itg.ti.com
To avoid this error declare variables as
my @row;
my $oid;
before using it, this would solve all your problems.
Urmil
-----Original Message-----
From: garrett esperum [mailto:shamonsflame@hotmail.com]
Sent: Tuesday, April 30, 2002 5:53 PM
To: Shah, Urmil
Cc: beginners@perl.org
Subject: RE: select from oracle and write to file
Thanks for the help!! I think it's almost there. This is what my script look
like now:
use strict;
use DBI;
open(TEXTFILE,">output.txt");
my $dbh = DBI->connect( 'dbi:Oracle:db',
'user',
'passwd',
{
RaiseError => 1,
AutoCommit => 0
}
) || die "Database connection not made:
$DBI::errstr";
my $sql = qq{ SELECT oid FROM bv_ep_project };
my $sth = $dbh->prepare ( $sql );
$sth->execute();
while( @row = $sth->fetchrow_array )
{
$oid=$row[0];
print TEXTFILE"$oid\n";
}
$sth->finish();
$dbh->disconnect();
And these are the errors I get:
Global symbol "@row" requires explicit package name at ./one.pl line 23.
Global symbol "$oid" requires explicit package name at ./one.pl line 25.
Global symbol "@row" requires explicit package name at ./one.pl line 25.
Global symbol "$oid" requires explicit package name at ./one.pl line 26.
Any input as to why this happens??
-garrett
>From: "Shah, Urmil" <ushah@ti.com>
>To: garrett esperum <shamonsflame@hotmail.com>
>Subject: RE: select from oracle and write to file
>Date: Tue, 30 Apr 2002 17:34:24 -0500
>
>
>open(TEXTFILE,">output.txt");
>
>my $sql = qq{ SELECT oid FROM bv_ep_project };
>my $sth = $dbh->prepare ( $sql );
>$sth->execute();
>
># Fetch the data from the DB using any method you like one of them is and
>print the output to a new file
>
> while( @row = $sth->fetchrow_array )
> {
> $oid=$row[0];
>
> print TEXTFILE"$oid\n";
>
> }
>$sth->finish();
>$dbh->disconnect();
>
> } #end of while loop
>
>This should work....
>
>Urmil
>
>-----Original Message-----
>From: garrett esperum [mailto:shamonsflame@hotmail.com]
>Sent: Tuesday, April 30, 2002 5:20 PM
>To: beginners@perl.org
>Subject: select from oracle and write to file
>
>
>Hello all,
>
>Solaris, Oracle 8.1.6, Perl 5
>
>How do I write my selected row from Oracle out to a new file? Below is what
>I have so far. I can select the row, but I don't know how to write it to a
>new file:
>
>
>#!/usr/local/bin/perl -w
>#
># REMEMBER! Set the environment variable: ORACLE_HOME=/path-to-oracle
>BEFORE
>
>running this script.
>#
>
>use strict;
>use DBI;
>
>my $dbh = DBI->connect( 'dbi:Oracle:db',
> 'user',
> 'passwd',
> {
> RaiseError => 1,
> AutoCommit => 0
> }
> ) || die "Database connection not made:
>$DBI::errstr";
>my $sql = qq{ SELECT oid FROM bv_ep_project };
>my $sth = $dbh->prepare ( $sql );
>$sth->execute();
>$sth->finish();
>$dbh->disconnect();
>
>Thank you for your help!!!
>
>-garrett
>
>_________________________________________________________________
>Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
>
>
>--
>To unsubscribe, e-mail: beginners-unsubscribe@perl.org
>For additional commands, e-mail: beginners-help@perl.org
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
Thread Previous
|
Thread Next