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:
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.");
}
However, if I removed the NVL so that the SQL looks like this:
$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?