kanwisch has asked for the wisdom of the Perl Monks concerning the following question:
Ok, I've got a script where I'm doing a simple SELECT out of a table. There're two date columns I want subtracted, and to deal with the mathematical NULL problem of getting NULL back, I've tried using the NVL function. Here's the SQL code:
$sSQL = qq{SELECT distinct (snickname), saccountnum, dtacctcreateddate +, (nvl(dtacctenableddate,to_date('01-jan-1900')))-(nvl(dtacctdisabled +date,to_date('01-jan-1900'))) as disableddiff, laccountid, sacctdisab +led FROM $gsAccountTable WHERE SAPP = '$gsApp' AND SOWNERID = '$sOwnerID' and DTACCTCREATEDDATE + IS not NULL and SACCTDISABLED <> 'DELETED' ORDER BY SACCTDISABLED};
However, after executing, it my cursor is apparently empty, because when I try to loop over the results (by hashref), it skips the loop. Here's the loop for curiosity's sake:
However, if I removed the NVL so that the SQL looks like this:while ($sRow = $sCursor->fetchrow_hashref) { $iCount++; $gsaInput{'LACCOUNTID'.$iCount} = $sRow->{LACCOUNTID}; $gsaInput{'SACCTNAME'.$iCount} = $sRow->{SNICKNAME}; $gsaInput{'SACCTNUM'.$iCount} = $sRow->{SACCOUNTNUM}; $gsaInput{'SACCTDATE'.$iCount} = $sRow->{DTACCTCREATEDDATE}; $gsaInput{'SACCTDISABLED'.$iCount} = $sRow->{DISABLEDDIFF}; &TestLog ("Assigning $sRow->{DISABLEDDIFF} to $iCount."); }
$sSQL = qq{SELECT distinct (snickname), saccountnum, dtacctcreateddate +, dtacctenableddate-dtacctdisableddate as disableddiff, laccountid, s +acctdisabled FROM $gsAccountTable WHERE SAPP = '$gsApp' AND SOWNERID = '$sOwnerID' and DTACCTCREATEDDATE + IS not NULL and SACCTDISABLED <> 'DELETED' ORDER BY SACCTDISABLED};
it seems to work fine (except those items with NULLS have no mathematical result). But at least the cursor's getting the data. Any thoughts on how I can get my cursor to receive data while still using the NVL function?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Oracle nvl function
by samgold (Scribe) on May 23, 2002 at 03:10 UTC | |
|
Re: Oracle nvl function
by kanwisch (Sexton) on May 22, 2002 at 20:30 UTC | |
by buckaduck (Chaplain) on May 22, 2002 at 21:38 UTC |