RE: Query Oracle, show results (need help!!)

From: Rob Hanson (rhanson_at_aptegrity.com)
Date: 06/08/04


To: 'jason corbett' <jcorbett000@yahoo.com>, beginners@perl.org
Date: Tue, 8 Jun 2004 16:12:22 -0400 


I think you should turn on errors... by debault DBI will supress them.

After the DB connection, put this...
$db->{RaiseError} = 1;

Once you do this you will see that your prepare failed, your SQL syntax is
not valid.

> select * from ban where row num < 100

It should be "rownum", not "row num".

Rob

-----Original Message-----
From: jason corbett [mailto:jcorbett000@yahoo.com]
Sent: Tuesday, June 08, 2004 3:53 PM
To: beginners@perl.org
Subject: Query Oracle, show results (need help!!)

Hello all. I am trying to log into an Oracle database, send this query {
select * from ban where row num < 100} and I am getting erros like:
 
can't call method 'execute' on an undefined value at (filename) line_number.
Got any suggestions?
 
 
using the following perl script:
 
#!/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'

#Note the variables for username and password must be username and passwd
ONLY!!
my $dbh = DBI->connect($database, $username, $passwd)
  or die "Can't connect to Oracle database: \n $DBI::errstr\n";

#Set up your sql statement that you want to run in Oracle
my $sql=qq(select * from ban where row num < 100);
 
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 || die "Couldn't execute statement";

while (my @record= $sth->fetchrow_array)
{
 for (@record){
  print ("@record");
}
print "\n\n";
}

$dbh->disconnect;
 
 
 

                
---------------------------------
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger



Relevant Pages

  • RE: ADO.Net Connection Pooling Problem with Oracle
    ... the CLR is releasing the connection to your database. ... the number of database sessions in Oracle seem to ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Connecting to an Oracle Database
    ... You can also use FrontPage, ... Click Add to Catalog under "Database Connections" ... Put in your Oracle connection string in the custom connections dialog ...
    (microsoft.public.sharepoint.windowsservices)
  • ADO connection to Oracle
    ... the runtime version, however, the program terminates with no error ... The program always stops at the connection to the database. ... connection is made using generic OLE DB, not the Oracle data provider. ...
    (microsoft.public.vb.database.ado)
  • Re: Oracle Database Access via IIS 6.0 ASP Pages on Windows 2003 Serve
    ... What type of connection are you using? ... what you are saying is something similar to: "my car doesn't ... I am using the Microsoft's ODBC Driver for Oracle ... > connection to an Oracle database. ...
    (microsoft.public.inetserver.iis)
  • Re: SQL Server 2000 (Application) Role accessed through ADO.NET
    ... >> The database role claims to answer my ... >> through the Connection Object of ADO.NET ... Then I execute the SQL statement passed to the method ...
    (microsoft.public.sqlserver.security)