On Tue, 17 Dec 2002 13:21:52 -0600 "Ford, Andy" <[EMAIL PROTECTED]> wrote:

> I'm getting an error running DBD::Oracle:
> 
> DBD::Oracle::db do failed: ORA-00906: missing left parenthesis (DBD
> ERROR:
> OCIStmtExecute/Describe) at ./trace.pl line 13.
> 
> The environment is perl 5.6.1 on Solaris 8 with DBI 1.32 and DBD-Oracle
> 1.12.
> 
> The script that produces the above error is just:
> 
> #!/opt/perl5/bin/perl -w 
> use strict;
> use diagnostics;
> use DBI;
> use DBD::Oracle;

Unless you want some constants from DBD::Oracle, you don't need to 'use'
DBD::Oracle specifically.

> my ($dbname,$user,$passwd) = qw(KONFIG *** ****);
> my $dev = $ARGV[0];
> BEGIN {
>           $ENV{ORACLE_HOME} = '/opt/oracle/product/8.1.6';
>           $ENV{ORACLE_SID} = 'KONFIG';
> }
> my $dbh = DBI->connect("dbi:Oracle:KONFIG", $user, $passwd);

You should either include { RaiseError => 1 } or check that the handle is
valid before using it.  For example:

   my $dbh = DBI -> connect( "dbi:Oracle:$inst", $user, $pwd )
      or die "Connect to $inst as $user failed: $DBI::errstr";
   $dbh -> {RaiseError} = 1;
or
   my $dbh = DBI -> connect( "dbi:Oracle:$inst", $user, $pwd,
      {AutoCommit => 0, PrintError => 0, RaiseError => 1} );
or
   my $dbh = DBI -> connect( "dbi:Oracle:$inst", $user, $pwd,
      {AutoCommit => 0, PrintError => 0, RaiseError => 0} )
      or die "Connect to $inst as $user failed: $DBI::errstr";
   # Explicitly test DBI method calls

> $dbh->do("SELECT uui FROM table device WHERE name = $dev");

"table" is not a valid table name.  "device" is probably being treated as a
table alias.

It is not safe to just paste a value into the SQL.  Look up placeholders in
the fine manual (perldoc DBI).

Whatever method you call, you should check it's return or test $DBI::err to
make sure there wasn't an error.

> $dbh->disconnect;
> 
> So it looks like I'm connecting OK, but the "do" fails.

do() is not appropriate for SELECT statements.  There are several examples
in the fine manuals (perldoc DBI and perldoc DBD::Oracle) and in
DBD-Oracle-1.12/Oracle.ex/.

I think the problem is that Oracle is trying to parse the misformed SQL as
a complex SELECT with a sub-SELECT; except that the '(' that starts the
sub-SELECT is missing.

-- 
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.


Reply via email to