I am writing a script that'll query the database, and I want to do 2 things:
1. Print it to screen with my desired format.
If I like what I see:
2. Print it to a file.
Any suggestions?
Here is my query for writing to a file:
______________________________________________________________
#!/usr/bin/perl -w
use strict;
use DBI;
# $ENV{"ORACLE_HOME"}="/orav101/oracle/8.0.6";
#Gather data for connecting to database:
print "Enter the database name that you want to connect to: ";
chomp (my $database_name1=<STDIN>);
print "Enter the username: ";
chomp (my $username=<STDIN>);
print "Enter the password: ";
chomp (my $passwd=<STDIN>);
#Must define the database here:
my $database="dbi:Oracle:$database_name1";
#Connecting to the database:database=<database_name1','$username','$passwd'
my $dbh = DBI->connect($database, $username, $passwd)
or die "Can't connect to Oracle database: \n $DBI::errstr\n";
$dbh->{RaiseError} = 1;
#Set up your sql statement that you want to run in Oracle
my $sql=qq( select * from ctn_inv where rownum <10
);
#Prepare the SQL statement for running and it'll be stored in Oracle buffer
my $sth=$dbh->prepare($sql);
#Execute the SQL statememt
$sth->execute;
my $outputme= "> /cygdrive/c/cygwin/my_Perl/basic_script/testfile1.txt";
my @record_list;
my $record;
while { @record_list = $sth->fetchrow_array;
}
open(TESTFILE1, $outputme);
foreach $record (@record_list)
{
print TESTFILE1;
}
close($outputme);
$dbh->disconnect;
---------------------------------
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger