Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
Programming

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;

This discussion was created by TechnoLust (528463) for no Foes, but now has been archived. No new comments can be posted.

Where my PL/SQL thugs at? (or HELP!!!!)

Comments Filter:
  • I suspect embezzlement. Investigate and fire your purchasing staff. Be a hero for fraud busting, get promoted.

  • I don't know Java all that well (that is java right?) but if I'm understanding you correctly I'va had the same problem a few times. The problem I had was that the data isn't NULL, it's ''. Make sense? In PHP I've gotten around that by using something similar to

    if (!isset($var) && $var != ''){
              foo;
    }
    • 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. :-)

    • Not Java... PL/SQL. Oracle PL/SQL to be precise. And the problem isn't in a NULL not matching, it's the rowcount not working.
  • Dude, I'm not seeing anything in particular in the fragments you sent. Send me a bigger chunk to my gmail, however, and I'll take a look. BTW, I'm not sure why you are doing this in two steps. Join the two tables, group on a set of stati, and use a having clause to filter out the POs not ready to be closed. You probably want to think about using "FOR UPDATE" in some of this SQL too.
  • Without understanding more, I'm with RevMike doing more of the work in the query instead of the code.

    That aside, you might try a test for NOTFOUND. PL/SQL is practically foreign to me, so I'm not really sure of this.
    • Begin
          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;
    • I'm thinking something like...

      SELECT PO.Document_id
      ,SUM(DECODE(POLI.Status, 'Cancelled', 0, 'Paid', 0, 1)) still_open
      FROM 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.

  • 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.

It is masked but always present. I don't know who built to it. It came before the first kernel.

Working...