Hierarchical RDBMS Query spanning across multiple tables with in clause

56 views Asked by At

I have a Product table. Each product has at least one version maintained in PROD_VERSION (ProdID references Product.ProdID)

Now each version of a Product can have 0 or many sub-products. The relationship is stored in ProdAssoc table (ParentVersionID references PROD_VERSION.version_D, childProdId references Product.ProdID)

Now while creating a new Product from UI, a user can choose zero or many child products.

I need to check if any existing Composite Product has the same set of atomic products(having no child product) as children directly or indirectly.

I've come up with

 SELECT level, view1.* FROM 
  (SELECT ps.ProdID pid, cpsn.ParentVersionID , cpsn.childProdId apid
    FROM Product ps, PROD_VERSION psv, ProdAssoc cpsn 
    WHERE psv.version_D = cpsn.ParentVersionID 
       AND ps.ProdID = psv.ProdID ) view1
   CONNECT BY prior pid = apid
   START WITH apid IN (318, 323, 320);

Any help/improvement in this regard will be highly appreciated.

Environment

DB: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production PL/SQL Release 12.1.0.2.0 - Production "CORE 12.1.0.2.0 Production" TNS for Linux: Version 12.1.0.2.0 - Production NLSRTL Version 12.1.0.2.0 - Production

Java: java version "1.7.0_07" Java(TM) SE Runtime Environment (build 1.7.0_07-b10) Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)

Server: Red Hat JBoss Enterprise Application Platform - Version 6.3.3.GA

OS: Linux kolps46 2.6.32-431.20.3.el6.x86_64 #1 SMP Fri Jun 6 18:30:54 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux

0

There are 0 answers