DBAsupport.com Forums - Powered by vBulletin
Results 1 to 10 of 23

Thread: Can someone help me on Cursor For Loops?!?!?!

Threaded View

  1. #13
    Join Date
    Mar 2006
    Posts
    11
    Quote Originally Posted by gandolf989
    This is a stupid assignment. What about writing a
    trigger that flags when someone is trying to cause a negative
    inventory? What about creating a package that contains all of your
    business logic? i.e. adding inventory, selling inventory, discounting
    inventory based on what isn't selling. What about writing a logging
    and error handling package? There are a lot of better projects that
    you could be working on besides this.

    --- end of rant ---

    You forgot the update in the second update
    statement. You should have a commit in your code. Do you
    want the word NULL or the value NULL. If you put it in quotes
    you will get the word NULL rather than the value NULL. You are
    also corrupting your data by setting it to '*'. You should have
    an overstock flag that gets set and unset as inventory is added
    and removed. This flag should probably get set through a trigger.

    Code:
    DECLARE
       CURSOR STK_CURSOR IS
          SELECT * FROM MM_MOVIE
             FOR UPDATE NOWAIT;
    BEGIN
       FOR STK_REC IN STK_CURSOR LOOP
          IF STK_REC.STK_FLAG > 75 THEN
             UPDATE MM_MOVIE
                SET STK_FLAG = '*'
              WHERE CURRENT OF STK_CURSOR;
          ELSE 
             UPDATE MM_MOVIE
                SET STK_FLAG = NULL
              WHERE CURRENT OF STK_CURSOR;
          END IF;
       END LOOP;
    
       COMMIT;
    END;
    /

    I agree about the assignment, there are so many more efficient ways of doing this it's mind boggling. I think they want students to be familiar with different ways of setting up condition statements so they can be "real world" ready after graduating. To make things worse this is an online class, so i dont even get to sit and chat with the teacher unless its through email or any other type of communication medium like that.

    I appreciate all of the help everyone has given me on this, its greatly appreciated.

    I want the value to be null not the word null.

    I ran the program it works, but nothing is being outputted to the stk_flag column
    Last edited by Jplaya2023; 03-17-2006 at 12:12 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width