Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8057741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:07:54+00:00 2026-06-05T09:07:54+00:00

I´ve been struggling for several days with a problem. I have a couple of

  • 0

I´ve been struggling for several days with a problem. I have a couple of tables in an Oracle DB (10g), one that shows a list of orders sorted by priority and the other an inventory of products. What I want to do is assign the available products to the orders based on the priority. My questions are:

  • Each order will receive only one product. How can I select only the orders that can receive a product based on the available existence?
  • To make the procedure more efficient, is there a way of storing the inventory changes while selecting the products, and apply the update at the end of the procedure?

Both tables will have thousands of items, so I think a PL/SQL stored procedure would be more efficient.

Thanks for your time and help.

PS: This is an example of my tables.

Orders
-------------------------------------------
| ID      |  Priority     |     Product
-------------------------------------------
| Order1  |    50         |        1
| Order7  |    48         |        3
| Order3  |    45         |        1
| Order2  |    40         |        1
| Order9  |    30         |        2
| Order4  |    15         |        3


 Inventory
-------------------------------------------
| ProductID |  Qty      
-------------------------------------------
| 1         |    2 
| 2         |    4 
| 3         |    1 

After running the stored procedure I need to get the following result and need to update the inventory.

-------------------------------------------
| ID      |  Priority     |     Product
-------------------------------------------
| Order1  |    50         |        1
| Order7  |    48         |        3
| Order3  |    45         |        1
| Order9  |    30         |        2

Updated Inventory
-------------------------------------------
| ProductID |  Qty      
-------------------------------------------
| 1         |    0 
| 2         |    3 
| 3         |    0 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:07:57+00:00Added an answer on June 5, 2026 at 9:07 am

    Yep a procedure would be the best way to handle the transaction.

    Open a cursor and populate it with your ordered Order table. Loop through the cursor and update the Inventory table as you fulfill the orders.

    CREATE OR REPLACE PROCEDURE update_oders (status OUT BOOLEAN)
    IS
        CURSOR orders
        IS
              SELECT id, priority, product
                FROM orders
            ORDER BY priority DESC;
    BEGIN
        status := FALSE;
    
        FOR cur_rec IN orders
        LOOP
            BEGIN
                SELECT COUNT ( * )
                  INTO inventory_count
                  FROM inventory
                 WHERE productid = cur_rec.product;
    
                IF inventory_count > 0
                THEN
                    BEGIN
                        UPDATE inventory
                           SET qty = qty - 1
                         WHERE productid = cur_rec.product;
    
                        INSERT INTO filledorder (id, priority, product)
                            VALUES (id, priority, product);
                    EXCEPTION
                        WHEN OTHERS
                        THEN
                            --log error about problem..
                            ROLLBACK;
                    END;
                ELSE
                    -- log some error or order inventory?
                    NULL;
                END IF;
            EXCEPTION
                WHEN NO_DATA_FOUND
                THEN
                    --log data;
                    NULL;
            END;
        END LOOP;
    
        COMMIT;
        status := TRUE;
    EXCEPTION
        WHEN OTHERS
        THEN
            -- log 
            ROLLBACK;
            status := FALSE;
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling with this for several days now and I ran out
Been struggling with this simple selector problem a couple of hours now and must
I've been struggling with this error for several days with little headway. Basically, I'm
I have been struggling with a nasty ANR problem with my app, which loads
So I've been struggling with web-services for a couple of days now, and It
I have for the last several years been struggling to understand why the Internet
Been struggling with this one I have the following DOM Structure: <ol id=add_images> <li>
Been struggling with this for a couple days now. Here's the set up -
I've been struggling with this for the last several hours: I have a nested
I've been struggling over this for several days now and can't crack it. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.