(@_@) Why are you calling the same SQL at least twice in the script?

You could do something like:
$dbh=$db->prepare("SELECT nvl(mb_award,0.00), nvl(mb_accept,0.00) FROM Items WHERE itemnum=? AND seller=? AND closef='1'"); $dbh->execute($form{'item'}, $fdnum); my ($mb_award,$mb_accept) = $dbh->fetchrow_array(); my $mb_amount_disp = $mb_award > 0.00 ? $mb_award : $mb_accept > 0.00 ? $mb_accept : 0.00; # Assume you have negative values
The most likely reason for your SQL query to fail is perhaps the null values in the columns. nvl(xxx,default) will return the default value if xxx is null.

As a reference, I have put down the following code as an example for database access:

use strict; use DBI; use DBD::Oracle qw(:ora_types); # Connect as Oracle $ENV{ORACLE_HOME}='/users/oracle/OraHome1'; my $dbh=DBI->connect("dbi:Oracle:MyDatabase","username","password"); # Select the some columns from the database my $sth = $dbh->prepare("select a as Alias, b as Bob from MyTable where c=?"); $sth->execute("Some Value"); # One convenient method is to use a hash reference while (my $res = $sth->fetchrow_hashref()) { # You can refer to values using the name of the column/alias # for example... my $alias = $res->{Alias}; my $bob = $res->{Bob}; .... } $sth->finish; $dbh->disconnect();

In reply to Re: DBI compare columns problem by Roger
in thread DBI compare columns problem by th3monk3y

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.