
Journal TechnoLust's Journal: Where my PL/SQL thugs at? (or HELP!!!!) 10
Here's the rundown. I loop through a list of Open POs and grab their ids. I used a cursor and that's gravy. So now I grab all the PO Line Items (stored in a different table) for each PO and check to make sure they are all Paid or Cancelled. If they are, I close the PO and adjust the budget. Groovy. The problem is that for some reason, we have a plethora of POs with no line items. So my FOR loop is never entered on these and my BOOLEAN doesn't get set to false. So when it gets down to the next section it enters to IF block and performs a SELECT INTO which explodes because there's nothing SELECTed to put INTO the variable.
So I'm thinking I'm all slick, I created another variable and set it to 0 and incremented it on ever iteration of the FOR loop. then I tested to see if it was 0 and if so, set my BOOLEAN to FALSE. It still bombed with an ORA-01403: no data found error. Here is what I have so far: (Statuses is a cursor.)
V_our_rowcount
:= 0;
FOR Row1 IN Statuses (Row0.Document_id) LOOP
V_our_rowcount:= V_our_rowcount + 1;
IF (Row1.Status IN ('Open', 'Ordered', 'Received', 'Invoiced') ) THEN
V_ready_to_close:= FALSE;
END IF;
END LOOP;
IF (V_our_rowcount = 0) THEN
V_ready_to_close:= FALSE;
DBMS_OUTPUT.Put_line ('No Rows, setting to False.');
END IF;
IF (V_ready_to_close = TRUE) THEN
--Do some cool stuff.
END IF;
POs without items? (Score:2)
I suspect embezzlement. Investigate and fire your purchasing staff. Be a hero for fraud busting, get promoted.
hrmm (Score:2)
if (!isset($var) && $var != ''){
foo;
}
Re:hrmm (Score:2)
Been there, done that, used NVL(Status, '') to get around it. Of course, you need to make sure that null and a zero-length string are logically equivalent for your purposes, which it looks like from umpty hundred miles away. And you can use this opportunity to impress the value of check constraints on your architects. :-)
Re:hrmm (Score:2)
Re:hrmm (Score:2)
SQL development is a different beast (Score:2)
Taking a stab (Score:2)
That aside, you might try a test for NOTFOUND. PL/SQL is practically foreign to me, so I'm not really sure of this.
Re:Taking a stab (Score:2)
Select foo
From bar
Where bletch > 42;
Exception
When NO_DATA_FOUND Then
Error_Handler(); --or null; if you just want to swallow the error.
End;
Re:Taking a stab (Score:2)
I'm thinking something like...
SELECT PO.Document_idFROM PurchaseOrder PO, PurchaseOrderLineItem POLI
WHERE PO.Document_id = POLI.Document_id
GROUP BY PO.Document_id
HAVING still_open = 0
This should yield a set of Document_ids that have only Canceled or Paid line items.
I hate that syntax (Score:2)
Argh, I'm getting to used to Transact SQL.
Can't you select into it?
SELECT variable + 1 INTO variable
I think that'll work.