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 7911501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:16:26+00:00 2026-06-03T13:16:26+00:00

I am not able to find the solution for my problem. I have 4

  • 0

I am not able to find the solution for my problem. I have 4 tables:

BomModule: This table represents a module in the database.

CREATE TABLE "BOMMODULE"
(
    "MODULEID" NUMBER(10,0) NOT NULL ENABLE,
    "ISROOTMODULE"     NUMBER(1,0) NOT NULL ENABLE,
    "MODULENAME"       VARCHAR2(255 CHAR),
    ...
)

BomItem: This table represents a leaf – or an item in the database.

CREATE TABLE "BOMITEM"
(
    "ITEMID"     NUMBER(10,0) NOT NULL ENABLE,
    ...
)

ModuleConnection: This table maps a module to another parent module. You can define the quantity of submodules that belong to a specific parent module.

CREATE TABLE "MODULECONNECTION"
(
    "ID"       NUMBER(10,0) NOT NULL ENABLE,
    "QUANTITY"   NUMBER(10,0) NOT NULL ENABLE,
    "SUBMODULE_MODULEID"   NUMBER(10,0) NOT NULL ENABLE,
    "PARENTMODULE_MODULEID" NUMBER(10,0) NOT NULL ENABLE,
    ...
)

ItemModuleConnection:
This table maps all leave-items to a module. Furthermore, you can define the quantity of items for one module.

CREATE TABLE "ITEMMODULECONNECTION"
(
    "ID"       NUMBER(10,0) NOT NULL ENABLE,
    "QUANTITY" NUMBER(10,0) NOT NULL ENABLE,
    "ITEMID"   NUMBER(10,0),
    "MODULEID" NUMBER(10,0),
    ...
)

As you can see from the table structure, items and modules are connected to each other and have different quantities. Due to the fact that those connections are very flexible, I am not able to create a SQL statement, that will provide me the total quantity for an item:

select quantity from ...... where itemId = xy;

The SQL statement should check all quantities from the item to the root module and multiply them:

2 x rootmodule (total 2)
-- 1x submodule 1 (total 2)
-- 2x submodule 2 (total 4)
---- 5x item 1 (total 20)
---- 6x item 2 (total 24)

Please help me create this sql statement, much appreciate your answer!

Constraints:

– It has to be a SQL statement (It is used in a Java application)
– Database is Oracle 11g

  • 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-03T13:16:27+00:00Added an answer on June 3, 2026 at 1:16 pm

    I was able to solve this problem by using Java, instead of SQL. This is my approach:

    /**
     * This recursive functions interates through the whole tree and checks if there are items and modules.
     * As soon as an item is found, it is multiplied with the module amount. The result is saved in a HashMap. 
     * This HashMap is being parsed in the end.
     */
    public HashMap<Integer, Integer> updateBom(HashMap<Integer, Integer> bom, BomModule module, int amount, BomHandling bh) {
        if(bom == null) {
            bom = new HashMap<Integer, Integer>();
        }
        // get all items for this parent module
        Collection<ItemModuleConnection> items = bh.getItems(module.getModuleId());
        Iterator<ItemModuleConnection> itemIterator = items.iterator();
    
        while(itemIterator.hasNext()) {
            ItemModuleConnection con = itemIterator.next();
    
            int itemQuantity = con.getQuantity() * amount;
    
            // if bom item already exists in bom list, get it and update quantity
            Integer currentItemQuantity = new Integer(0);
            if(bom.containsKey(new Integer(con.getItem().getItemId()))) {
                currentItemQuantity = bom.get(con.getItem().getItemId());
                bom.remove(bom.get(con.getItem().getItemId()));
            }
            bom.put(con.getItem().getItemId(), currentItemQuantity + itemQuantity);
        }
    
        // get all modules for this parent module
        Collection<ModuleConnection> modules = bh.getConnections(module.getModuleId());
        Iterator<ModuleConnection> moduleIterator = modules.iterator();
    
        // set the quantity of the module by multiplying it with the amount
        while(moduleIterator.hasNext()) {
            ModuleConnection moduleCon = moduleIterator.next();
            int moduleQuantity = moduleCon.getQuantity();
            updateBom(bom, moduleCon.getSubModule(), moduleQuantity * amount, bh);
        }
        return bom;
    }
    

    Before I print the single Items, I call this updateBom()-function and then retrieve the values from the HashMap:

    HashMap<Integer, Integer> bom = updateBom(null, bomModule, 1, bh);
    Iterator<Map.Entry<Integer, Integer>> entries = bom.entrySet().iterator();
    
    while (entries.hasNext()) {
    
        Map.Entry<Integer, Integer> bomEntry = entries.next();
        BomItem item = bh.getBomItem(bomEntry.getKey());
        Integer itemAmount = bomEntry.getValue();
    
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have not been able to find a solution to my problem yet. What
I'm just not able to find a solution to this. I have the following
I am trying to create a customized UISearchBar. I am not able to find
I have tried rectifying the code below. But I am not able to find
Maybe this has been answered before, but I was not able to find it.
I have this problem since a long time and I cannot find anything to
I’m having a very basic problem here which I was not able to find
I have a small problem but couldn't find solution for that. I have founded
I am not able to find a way to set TransactionIsolation in ejb. Can
I am not able to find the reason of a crash in my iphone

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.