aennen has asked for the wisdom of the Perl Monks concerning the following question:

Ok I am at a loss I have a query that work in one perl program but not in the other, I have stripped the code down to the bare essentials and have looked for any differences between the one that works and the one that does not but can find no problems. I get an Oracle error on this, if I select on a given field no error but the print only returns info if the data is half or less of the column size.... Am I missing something obvious here ????
#!/usr/bin/perl use DBI; my @listOfPaths; my @listOfNames; my %dbf; my $linkpage; my %rels=(); my %relsdt=(); my %vals=(); my $dbh; $ENV{"ORACLE_HOME"}="ORACLE_HOME=/oravl01/oracle/8.0.6/"; $ENV{"TWO_TASK"}="nxt1"; &sqlConnect("alan1", "alan1"); &getRef; &sqlDisconnect; ###################################################################### +############# sub sqlConnect() { $connectString=join '/', $_[0], $_[1]; $dbh = DBI->connect('dbi:Oracle:',$connectString); unless ($dbh) { &showSQLError($DBI::errstr); } } ###################################################################### +############# sub sqlDisconnect() { $dbh->disconnect; } ###################################################################### +############# sub getRef() { $statement = "select * from OPEN_ISSUES order by OI_REFERENCE asc" +; print "$statement\n"; $rqry = $dbh->prepare($statement) or &showSQLError($dbh->errstr); $rqry->execute or &showSQLError($DBI::errstr); &showSQLError($DBI::errstr); unless ($dbh) { &showSQLError($DBI::errstr); } print "\n#"; while($oir=$rqry->fetchrow_hashref) { print "\n- $oir->{'OI_REFERENCE'}"; } print "\n#\n"; $rqry->finish or &showSQLError($DBI::errstr); print "- $oir->{'OI_REFERENCE'}\n"; } sub showSQLError() { print "<SCRIPT> alert('$_[0]');</SCRIPT>"; }

Replies are listed 'Best First'.
Re: Perl : DBI and Oracle
by chromatic (Archbishop) on Jan 09, 2003 at 23:00 UTC

    Mind some constructive style suggestions?

    First, I'm leery of declaring all of your variables at the start. They're effectively global -- at least, shared among all subroutines. That gives you some of the same drawbacks as global variables, most notably that you can whack one somewhere and not notice it until you reach another part of the code.

    Second, calling subroutines with the leading ampersand is almost always wrong. It's right in this case, but only because you're using prototypes. Since you do want to pass arguments to the subs, drop the prototypes, and you can get rid of the ampersand. I suggest avoiding prototypes unless you want to act like a built-in operator. In other words, most of the time, you don't need them.

    Besides that, it's generally a lot clearer to use named arguments instead of accessing elements of @_ directly. The exception is when you want to make it very clear that you're modifying an argument in place.

    Here's how I would have written things:

    #!/usr/bin/perl -w use DBI; use strict; $ENV{"ORACLE_HOME"}="ORACLE_HOME=/oravl01/oracle/8.0.6/"; $ENV{"TWO_TASK"}="nxt1"; my $dbh = sqlConnect("alan1", "alan1"); unless ($dbh) { showSQLError( $DBI::errstr ); exit; } getRef( $dbh ); sqlDisconnect( $dbh ); sub sqlConnect { my ( $username, $password ) = @_; my $connectString = join '/', $username, $password; return DBI->connect('dbi:Oracle:',$connectString); } sub sqlDisconnect { my $dbh = shift; $dbh->disconnect; } sub getRef { my $dbh = shift; my $statement = "select OI_REFERENCE from OPEN_ISSUES order by OI_ +REFERENCE asc"; print "$statement\n"; my $sth = $dbh->prepare($statement) or showSQLError($dbh->errstr); $sth->execute or showSQLError($sth->errstr); print "\n#"; while(my ($oir) = $sth->fetchrow_array) { print "\n- $oir"; } print "\n#\n"; } sub showSQLError { print "<SCRIPT> alert('$_[0]');</SCRIPT>"; }

    If you set the RaiseError attribute on the database handle, you can do away with showSQLError too.

Re: Perl : DBI and Oracle
by rbc (Curate) on Jan 09, 2003 at 19:38 UTC
    Are any of the columns you are selecting of type long?
    Or contain large amount of text?
    If so you check this node out.

      I was thinking that too (long columns or LOBs) but when I test that I get an error in addition to not getting any rows back. I don't see anything in the sample code turning off RaiseError or PrintError which, I thought, were on by default. So while a long column would do it, why no error?

      At any rate, a description of the table being queried would be useful here, as well as any output.

        Figured it out, my env set for ORACLE home was wrong causing this problem.
        $ENV{"ORACLE_HOME"}="ORACLE_HOME=/oravl01/oracle/8.0.6/"; Should be $ENV{"ORACLE_HOME"}="/oravl01/oracle/8.0.6/";
        Seeing without seeing.... Thanks Alan