I need to use data collected from a query

From: Jason Corbett (jcorbett000_at_yahoo.com)
Date: 06/09/04


Date: Wed, 9 Jun 2004 11:58:55 -0700 (PDT)
To: beginners@perl.org

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



Relevant Pages

  • Re: ADO data control
    ... Another way to test your query would be to try ... instinctively think that the database is probably not normalized. ... written on the topic of normalization, and one you might like is "Database ... Then the SQL statement and the existing WHERE and ORDER BY calculations ...
    (microsoft.public.vb.controls)
  • Re: Design View
    ... Can we assume that you put your database is a "trusted" location? ... Try the query again. ... it should print the SQL statement of the query into ... The same query opens fine in design view in Access 2000. ...
    (microsoft.public.access.queries)
  • Re: Design View
    ... Someone else may be able to provide a suggestion. ... I also checked references and they seemed fine for that database, ... Okay, Bob, the query contains the reserved word DATE as a field name. ... you may be able to get the SQL statement in A2007 opening the ...
    (microsoft.public.access.queries)
  • Re: Design View
    ... I also checked references and they seemed fine for that database, ... Okay, Bob, the query contains the reserved word DATE as a field name. ... you may be able to get the SQL statement in A2007 opening the ... The same query opens fine in design view in Access 2000. ...
    (microsoft.public.access.queries)
  • Re: Design View
    ... If it would be any help, I could e-mail you the database. ... Switch the problem query to SQL View, ... you may be able to get the SQL statement in A2007 opening the ... The same query opens fine in design view in Access 2000. ...
    (microsoft.public.access.queries)