Recursive relationship in oracle

I have a table that stores customer, the related client and the number of connected clients.

The related client may have even more related customers that it is like a recursive relationship.

I wanted to know all the clients connected (until the last customer related) for a client.

I had tried something like below who gave me an error loop in the user data

Select *.

of (connect_by_root (cus_id) select cus_id, rel_cus_id)

of RELATED_TABLE

Start with rel_cus_id is not null

Connect prior cus_id = rel_cus_id)

where cus_id <>rel_cus_id;

Statistics on the table:--

---------------

This volume is 2,00,000 records.

Create table

--------------

CREATE TABLE RELATED_TABLE

(CUS_ID, VARCHAR2 (09))

REL_CUS_ID VARCHAR2 (09),.

COUNT_OF_REL_CUST NUMBER (12));

Samples: -.

---------------

INSERT INTO RELATED_TABLE VALUES ('402758970', '898196448', 3);

INSERT INTO RELATED_TABLE VALUES ('402758970', '855115206', 3);

INSERT INTO RELATED_TABLE VALUES ('402758970', '850353774', 3);

INSERT INTO RELATED_TABLE VALUES ('898196448', '691094946', 3);

INSERT INTO RELATED_TABLE VALUES ('898196448', '404636299', 3);

INSERT INTO RELATED_TABLE VALUES ('898196448', '402758970', 3);

INSERT INTO RELATED_TABLE VALUES ('855115206', '870397045', 3);

INSERT INTO RELATED_TABLE VALUES ('855115206', '855115206', 3);

INSERT INTO RELATED_TABLE VALUES ('855115206', '402758970', 3);

CUS_ID REL_CUS_ID COUNT_OF_REL_CUST

402758970 898196448 3

402758970 855115206 3

402758970 850353774 3

898196448 691094946 3

898196448 404636299 3

898196448 402758970 3

855115206 870397045 3

855115206 855115206 3

855115206 402758970 3

OUTPUT:-

--------------------

402758970 898196448

402758970 855115206

402758970 850353774

402758970 691094946

402758970 404636299

402758970 870397045

402758970 855115206

We know not what you need, but it looks like:

SQL > SELECT DISTINCT CUS_ID '402758970',

2 REL_CUS_ID

RELATED_TABLE 3

4. START WITH CUS_ID = '402758970'

5. CONNECT NOCYCLE PRIOR REL_CUS_ID = CUS_ID

6.

CUS_ID REL_CUS_I

--------- ---------

402758970 898196448

402758970 691094946

402758970 870397045

402758970 402758970

402758970 404636299

402758970 850353774

402758970 855115206

7 selected lines.

SQL >

SY.

Tags: Database

Similar Questions

  • Loading of an oracle table empty that has recursive relationship - ETL

    Hi, I have an empty table, called programs. The columns are Short_Name, Long_Name, Pgm_ID (PK), PArent_Pgm_ID (FK). The parent_Pgm_ID and the Pgm_ID are recursive relationship. I have 3 lines, I am loading.

    1, abc, one, 25
    2, def, d, 35
    3, efg, e, 12

    I am struck by the constraint violation. I 25, 35, 12 Pgm_ID is loaded first inorder to charge the three lines above. My problem is that they might have different from Parent_Pgm_ID, should I continue to ride all the way, until all the records are synchronized.

    Can you please suggest me any solution on how to manage this ETL?

    Thanks for your time and your help.

    >
    Hi, I have an empty table, called programs. The columns are Short_Name, Long_Name, Pgm_ID (PK), PArent_Pgm_ID (FK). The parent_Pgm_ID and the Pgm_ID are recursive relationship. I have 3 lines, I am loading.

    1, abc, one, 25
    2, def, d, 35
    3, efg, e, 12

    I am struck by the constraint violation. I 25, 35, 12 Pgm_ID is loaded first inorder to charge the three lines above. My problem is that they might have different from Parent_Pgm_ID, should I continue to ride all the way, until all the records are synchronized.

    Can you please suggest me any solution on how to manage this ETL?
    >
    You cannot load a line with a 'parent' pointing 'id = 25' if there is no line in the table with 'id = 25'.

    Disable the constraint.

    Load the data.

    Select the constraint.

  • Generation of entity - relationship with Oracle SQL Developer.

    Is it possible to generate an entity - diagram of the relationships of Oracle SQL Developer?

    Thanks in advance,
    Jaime.

    If you are willing to pay the 3000 quid per head (+ annual support costs), take a look at [Oracle SQL Developer Data Modeling | http://www.oracle.com/technology/products/database/datamodeler/index.html].

    Have fun
    K.

  • Is there a way to fill the boss way recursive/dynamically in oracle 10g

    Hello

    I want to complete the following template and then use the result as a virtual table in oracle 10g.

    SELECT 2 FROM DUAL;

    UNION ALL

    4. SELECT FROM DUAL;

    ALL UNIONL

    8. SELECT FROM DUAL;

    .

    .

    .

    .

    UNION ALL

    . SELECT POWER (2.61) FROM DUAL;

    Is it possible that I can use the recursion or dynamic query with "with clause" and avoid writing all these statements.

    Thank you

    YG

    Hi GY,.

    In 10g, you can use a clause of the TYPE:

    SELECT nbr

    OF THE DOUBLE

    MODEL

    DIMENSION (2 d)

    MEASURES (number 0)

    RULES ITERATE (61)

    (nbr [ITERATION_NUMBER] = power (2, ITERATION_NUMBER + 1))

    ORDER BY nbr;

    From 11 g 2, you can use a WITH recursive clause:

    WITH v (n, lvl) AS (SELECT 2 n, 1 lvl FROM DUAL

    UNION ALL

    SELECT 2 * n, 1 + lvl

    V

    WHERE the lvl<=>

    )

    Select n v

  • Recursive relationship

    Hi all

    I have an Org table with a column ID organization and I also have a column as Parent-org. In my logical model I show it as a recursive relation ship. How should I design this in the physical table?

    Thank you for your time and your help.

    MANAGER_ID référenceriez EMPLOYEE_ID in the same table

  • Convert recursive with SQLServer Oracle clause

    I converted the following query to SQLServer 2005 to Oracle10g, but the column of factors is not correct:

    SQLServer
    WITH Factor (Code, StartDate, EndDate, Rate, Ranks, Factors) AS
    (
         SELECT Code, StartDate, EndDate, Rate, Ranks, CONVERT(FLOAT, 1.0)
         FROM #SplitDateRangeRank
         WHERE Ranks = 1
         UNION ALL
         SELECT S.Code, S.StartDate, S.EndDate, S.Rate, S.Ranks, CASE WHEN S.Rate > 0 THEN F.Factors / S.Rate ELSE F.Factors END
         FROM #SplitDateRangeRank S
         JOIN Factor F
         ON S.Code = F.Code
         AND S.Ranks = F.Ranks + 1
    )
    
    INSERT INTO #PrcAdjTemp
    SELECT Code, 1, StartDate, EndDate, Factors
    FROM Factor
    Oracle
      INSERT INTO tmpPrcAdj (Code, AdjType, StartDate, EndDate, Factor)
      WITH Factor AS
      (
           SELECT Code, StartDate, EndDate, Rate, Ranks, 1.0 Factors
           FROM tmpSplitDateRangeRank
       )
       SELECT Code,1, StartDate, EndDate, CASE WHEN Rate > 0 THEN Factors / Rate ELSE Factors END   
       FROM Factor
           start with Ranks = 1
       connect by code = prior code
       and  ranks = prior ranks +1;
    Need help!

    Try:

    INSERT INTO tmpPrcAdj (Code, AdjType, StartDate, EndDate, Factor)
    select Code,AdjType, StartDate, EndDate,Factors
    From tmpSplitDateRangeRank
    Model
      Partition By (Code)
      Dimension By (Ranks)
      Measures (Rate, 1 as Factors, 1 as AdjType, StartDate, EndDate)
      RULES
        (
         Factors[Ranks>1]=case when Rate[cv()] > 0 then Factors[cv()-1]/Rate[cv()] else Factors[cv()-1] end
        )
    
  • SQL Developer / Data Modeler - lost visual on the relationships between the tables

    11 GR 2 DBMS / SQL Developer 4.0.3

    In SQL Developer, using the Data Modeler I lost the visuals 'lines' (one to several, etc.) which show the PK to FK relationship between different tables from one of my patterns of relationship.  I know they exist - I'm sure it's my fault--put out something that I don't have.

    I looked on the web but without SOAP.  Can anyone tell me if it is a property and (as applicable) how to re - turn on the property.

    Thanks in advance.

    Barry D.

    Sorry - I found it - the relationship lines were VERY clear yellow and I could barely see it.

    Article by Jeff Smith on the model configuration screen has been very useful in this regard.

    http://www.thatjeffsmith.com/archive/2013/01/Configuring-display-of-model-relationships-in-Oracle-SQL-Developer-Data-Modeler/

    Thank you Jeff (again).

    Barry D

  • How to print barcodes in Oracle XML Publisher report

    Hello

    We have a report of rdf that prints the bar code in the start page based on a custom procedure of MarkView. It works well with Oracle Reports.

    But given that this report was a matrix report, we change it a linear relationship by Oracle XML Publisher report.

    We have every possible thing in the new Oracle XML report... But we are not able to print data from barcode which is BLOB in the XML report...

    Can someone help me on this? We have dates UAT at the corner...

    We have a RTF model.

    Help as soon as possible.

    Thank you

    AFA

    Hello

    I even referring to this blog.

    How to create a report with a field of image (.jpeg). Maniacs Oracle & #039; Notes

    The bar code is original

    Thank you and best regards,

    AFA

  • What is the official reporting tool Oracle JDeveloper ADF applications.

    Hi all
    I'm on the migration of Oracle Forms and Oracle JDeveloper ADF reports.
    I have read several books on JDeveloper and ADF and I take. Now what I will use to create reports; tool Oracle to create reports, that is tightly integrated with JDveloper and ADF comparable to the relationship between Oracle Forms and Oracle reports.
    I will be grateful for your response.
    Best regards,
    Denis Ojok

    There is no tool tightly coupled with jdev. Tool of oracles of choice would be BI Publisher (I guess). However, you can use the reports jasper or any other tool to report as well.

    Timo

  • How to create the Group of cache for many to many relationship tables?

    Hi, Chris,.
    Page 4-4 < < the user manual of the Oracle Database Cache in memory > > there is a saying,
    A child table cannot reference multiple parent tables.
    If there is a many-to-many relationship table in Oracle and I want to cache in TT, there is not a la carte approach that?
    Or I have to logically break his references to the two tables in one of them?
    I forgot to mention that I have a root table and one of its child tables is a many-to-many relationship table.

    Yes, that's correct. You can not exactly this model in TimesTen. You to omit some of the relationships so that things are defined in TimesTen as a pure parent/child relationship. You can also consider putting the tables into groups separate cache. Of course, there are consequences to this:

    1. the 'missing' relationship cannot be run by TimesTen. The application must respect/run it. If this is not some updates may not to be propagated to Oracle if they violate the relationship in Oracle.

    2 If the parallel AWT is configured (to improve the performance of spread) it will not be used for all tables where they lack of relationships. All updates to the tables in the order will apply.

    Chris

  • Subquery recursive factoring... bug? or my own personal ignorance?

    I tried to create a list of all the dates in the current month using a factor of recursive subquery. (Oracle 11.2)
    I know how to do this by other methods; the question is: what happens with this example "WITH"?

    Here is my attempt to create from the list:
    with
      date_list ( crnt_mnth_date )  as
        ( select  cast ( trunc(sysdate,'MM') as date )  from dual
          UNION ALL
          select  crnt_mnth_date + interval '1' day 
            from  date_list 
           where  to_char(crnt_mnth_date,'MM') = to_char(sysdate,'MM')
        )
    select  *  from  date_list ;
    Recursion must add a day to the previous date and continue for the generated dates are in the same month
    as the date current (sysdate). All I get is the first day of the month. To try to understand this, I added the
    sequence "n". To my surprise the recursion is subtracted rather than add one day every hour.
    with
      date_list ( n, crnt_mnth_date )  as
        ( select  1,  cast ( trunc(sysdate,'MM') as date )  from dual
          UNION ALL
          select  n+1,  crnt_mnth_date + (interval '1' day)  as crnt_mnth_date
            from  date_list 
           where  n < 9
        )
    select  *  from  date_list ;
    And... Change the '+' for a '-' always subtract one day every once - no change.
    Obvious BUG? Or am I just confused on how it works?

    Hello

    I heard that the recursive new WITH function of clause is buggy, especially when the DATEs are involved.
    I get the same results (unexpected) you do.

    A very similar request, using only numbers, performs wotk as expected:

    with
      date_list ( n, crnt_mnth_num )  as
        ( select  1,  20010501   from dual
          UNION ALL
          select  n+1,  crnt_mnth_num + 1  as crnt_mnth_num
            from  date_list
           where  n < 9
        )
    select  *  from  date_list ;
    

    Outptu:

    `       N CRNT_MNTH_NUM
    --------- -------------
            1      20010501
            2      20010502
            3      20010503
            4      20010504
            5      20010505
            6      20010506
            7      20010507
            8      20010508
            9      20010509
    
  • Need help - financial Oracle 11i vs (payable Oracle and Oracl pay) r12

    Hi all

    I am beginner in Oracle Application and request your help answering my questions.

    Background:
    Three years ago, my company intended to implement ERP Oracle Financials.
    To facilitate the plan, an open call for tenders was created to find the best implementation of the company at an affordable price.
    The tender was created when Oracle Financials 11i.
    When the contract was signed 2 years ago by my company and the winning company, it is mentioned that the installed version must be the last.
    The answer to the needs, the winning company said that payment activity will be facilitated by Oracle Payable.
    Now, the project is going and the Oracle has the version of recommendation 12.

    Problem:
    To 11i, there was only a single module related to the activities of payment, that is Payable to Oracle.
    Recommendation 12, Oracle has a new module, i.e. Oracle payment, which was the subdomain of Oracle Payable.

    Question:
    1. is my view on the relationship between Oracle and Oracle payment payable above correct?
    2 - is my company has the right to ask for payment of the Oracle installation?
    3. If the answer to the number 2 is Yes, what is the basis for this?

    Thanks for the explanation.
    Sorry if I ask a simple question.

    Kind regards
    Dodydh

    Published by: 840286 on February 28, 2011 03:28

    Hi Dodydh,

    I'm afraid, your statement "Oracle to recommendation 12, a new module, i.e. Oracle payment, which was the subdomain of Oracle to pay." is not correct.

    Oracle payments is a version upgrade of Oracle 11i iPayments and this module is supposed to use Self service modules. But lots of payment which is part of the creditors of the Oracle was moved to Oracle payments.

    You may very well ask to implement payment lots (process related to the disbursement of funds) but not all of the module.

    Please let me know if you need more information.

    Kind regards
    Sridhar

  • Oracle CRM at level 11.5.10.2 to Release 12

    Hello

    I have 2 questions:

    (1) we are on Oracle EBS 11.5.10.2. I want to know how to Release 12 Oracle CRM 11.5.10.2. I went through Metalink note # 1081433.1 which shows how to apply the management of customer relationship of Oracle © 12.1.3 (R12. CC_PF. B.Delta.3) which can be done on the existing environment to R12.1.

    But could not find any documents and information on the upgrade of 11-R12. Please help me with the information and what path is available to upgrade to CRM.

    (2) can upgrade us all CRM module in 11.5.10.2 Release 12.

    Please help me. Thank you.

    Abdulla,

    There is no precise answer to your question because it depends on your configuration, the configuration, the number of nodes, physical resources, the number of modules etc. The best practice for estimating the time to upgrade is to clone your production instance to test the instance, upgrade the test instance and estimate the time yourself.

    Thank you
    Hussein

  • Check if the Oracle Client is 64-bit Mode

    Hello

    I have a bit of Windows Server 2008 x 64 with Reporting Services x 64 bit.

    I have a relationship with oracle connection. First, I installed 10203_vista_w2k8_x86_production_client.zip (http://download.oracle.com/otn/nt/oracle10g/10203/10203_vista_w2k8_x86_production_client.zip), but in Reporting Services, I get the following error: "trying to load the Oracle client libraries threw BadImageFormatException. This problem occurs when you run with the 32-bit Oracle components customer installed 64 bit mode"

    Then I installed 10204_vista_w2k8_x64_production_client.zip (http://www.oracle.com/technology/software/products/database/oracle10g/htdocs/10203vista.html), but I have the same problem.

    How to check if Oracle Client runs in bits of x 64 or x 86?

    Saludos,

    It is not a 32-bit or 64-bit 'mode', you have the client client software or 64 bit 32 bit.

    The first thing to do is to check the process in the Task Manager to confirm if it is 32-bit or 64-bit (32-bit to a * 32 next to the process name).

    Regarding the inspection of a facility of the customer trying to tell if it's 32-bit or 64-bit, I don't know one other surefire way knowing what you have installed. You can consult the register, a 32-bit home will be located in HKLM > software > WOW6432Node > Oracle, considering that a 64-bit home will be in HKLM > software > Oracle and then you can check the path to the House to try to deduce if it is 32 bit or 64 bit depending on the location of the dll.

    If you have 32-bit and 64-bit client installed, I don't have a good top of my head that may cause for why you will get this error. The OS does a good job of loading the 32-bit dll for 32-bit processes and 64 for 64.

    Are two homes in your PATH environment variable? Did you restart the application or restart after the addition of a new home?

    You can use tools such as Process Explorer or Process Monitor to see what dlls are loaded (or attempted to be loaded).

    It will be useful,
    Greg

  • CONNECTION BY level/prior/root

    Hi all

    I'm trying to CONNECT BY level/prior/root. But I can barely decipher what it actually does. I think it is a very useful method provided by oracle and can have several uses. can someone help me on this please.

    I googled on this topic but everywhere I could find only employee and manager problem that will be solved by query below.
     SELECT employee_id, last_name, manager_id
       FROM employees
       CONNECT BY PRIOR employee_id = manager_id;
    But if we just query as below, we can get the employee and his manage without CONNECT BY.
    SELECT employee_id, last_name, manager_id
       FROM employees;
    Other queries is obtained to connect by is below, but he could not also include:
     select SYSDATE-41 + level - 1 the_date
                                from dual
                              connect by level <= SYSDATE - SYSDATE-41 + 1
    Please help me.

    Published by: J2EE_Life on December 6, 2011 08:12

    J2EE_Life wrote:
    Hi all

    I'm trying to CONNECT BY level/prior/root. But I can barely decipher what it actually does. I think it is a very useful method provided by oracle and can have several uses. can someone help me on this please.

    I googled on this topic but everywhere I could find only employee and manager problem that will be solved by query below.

    SELECT employe_id, last_name, manager_id
    Employees
    CONNECT BY PRIOR employee_id = manager_id;

    But if we just query as below, we can get the employee and his manage without CONNECT BY.

    SELECT employe_id, last_name, manager_id
    Employees;

    In fact, those who are not the same.
    If you use the standard table of hr.employees, the CONNECT BY query above returns 315 lines, but the secoind query return lines only 107.

    CONNECTION is useful to show the recursive relationships. It can show you, for example, not only that reports directly to a data manager, but the whole hierarchy of persons under a given head. For example, the following shows the hierarchy starting with an employee named "Rooster":

    SELECT  employee_id, last_name, manager_id
    ,     LEVEL                         AS lvl
    ,     SYS_CONNECT_BY_PATH (last_name, '/')     AS path
    FROM    hr.employees
    START WITH      last_name          = 'De Haan'
    CONNECT BY       PRIOR employee_id      = manager_id;
    
    SELECT     SYSDATE - SYSDATE-41 + 1
    FROM DUAL;
    

    Output:

    EMPLOYEE_ID LAST_NAME  MANAGER_ID LVL PATH
    ----------- ---------- ---------- --- --------------------------
            102 De Haan           100   1 /De Haan
            103 Hunold            102   2 /De Haan/Hunold
            104 Ernst             103   3 /De Haan/Hunold/Ernst
            105 Austin            103   3 /De Haan/Hunold/Austin
            106 Pataballa         103   3 /De Haan/Hunold/Pataballa
            107 Lorentz           103   3 /De Haan/Hunold/Lorentz
    

    Very briefly, here's how it works.
    The result set of a query CONNECT BY is the UNION ALL of several queries, all sharing a common SELECT clause.
    Any line that meets the conditions of the START WITH clause is supposed to be at LEVEL 1. So you can think of the first branch of the UNION of ALL being (in this case):

    SELECT  employee_id, last_name, manager_id
    ,     LEVEL                         AS lvl
    ,     SYS_CONNECT_BY_PATH (last_name, '/')     AS path
    FROM    hr.employees
    WHERE   last_name     = 'De Haan'
    UNION ALL ...
    

    Other rows in the result set will be LEVEL = N if the conditions of the CONNECT BY clause, where the PRIOR operator refers to any line level = N - 1.
    For example, the line with name = "Hunold" satisfies the condition to connect BY when the FIRST line is the line where last_name = "Rooster", Hunold is in the game with the LEVEL of results = 2.
    Another example: the line with name = 'Lorentz' meets the condition to connect BY when the FIRST line is the line where last_name = "Hunold", Hunold is in the result set with LEVEL = 3.
    This is a classic example of a tree structure, where the rows in the table are connected to other lines in a parent-child relationship. In a tree, each row has 0 or 1 of the parents, but a line can have any humber children. Haan has 0 parent and 1 child (that is, Hunold). Hunold has 1 parent (De Haan) and 4 children. CONNECT BY queries are useful to deal with the trees like this, especially when the parent-child relationship may extend to a number any levels.

    Other queries is obtained to connect by is below, but he could not also include:

    Select the level - 1 the_date + SYSDATE-41
    of the double
    connect by level<= sysdate="" -="" sysdate-41="" +="">

    I don't understand whether you.
    SYSDATE-SYSDATE is just 0
    0 - 41 + 1 is just-40, so you might as well say:

    select SYSDATE-41 + level - 1 the_date
                                from dual
                              connect by level <= -40;
    

    In addition, LEVEL is always a positive integer, then the CONNECT BY State will never have the value TRUE, and if the CONNECT BY clause can never be TRUE, there is no reason to have a CONNECT BY clause.
    A more reasonable request is:

    SELECT     SYSDATE + LEVEL - 1     AS the_date
    FROM      dual
    CONNECT BY     LEVEL     <= 4     -- or any positive number
    ;
    

    which produces this output, the given number of days (4 in this example) from today:

    THE_DATE
    --------------------
    06-Dec-2011 11:08:24
    07-Dec-2011 11:08:24
    08-Dec-2011 11:08:24
    09-Dec-2011 11:08:24
    

    This is a very common way to generate a Counter of Table (a table, or, as in this case, a result set, that matters). For example, if you need for the aggregates per day in a table and you want to show 0 for days that never exist in the table, then you outer join in a table of counter like the one shown above.
    This is a common use of CONNECT BY, but this is an unusual exception to the rules that is prohibited govern CONNECT BY queries. I suggest you uderstand how the query on hr.employees, above, the work before you start trying to figure out how it works.

    Published by: Frank Kulash, December 6, 2011 11:15

    The pages below are introductions to CONNECT BY:
    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:489772591421
    http://Philip.Greenspun.com/SQL/trees

Maybe you are looking for

  • Re: Anyone here heard spyware named ANTIVIRUS 7

    Anyone here heard spyware named ANTIVIRUS 7?I discovered this dish during site reading, a popup window IE7 and me blablabla, pc in danger and if! If so, how do I know my laptop suffered or not?And how to remove? Can Macfee scan this dishes and can Ma

  • "Bluetooth is not ready", after a new installation on Qosmio X 770

    Hello I have a Qosmio x 770 and I was pretty stuped to uninstall the bluetooth drivers and then re install.When I re installed them I installed Atheros filter first then the bluetooth stack and now I get the error whenever I try to add a new connecti

  • Tecra A6 - memory remapping with new BIOS?

    Does anyone know if it is possible to upgrade the bios on a Tecra A6 to enable the memory remapping so that all 4 GB can be used? Shaun

  • HP-g009ax: disk hard no error

    HelloHere is the error message I received - with drive hard test - what does this mean?Test Drive: 1INTELLIGENT control: FAILUREFAILURE ID: 9TU3HK-7MT869-XD7V7G-60F503

  • HP Laser Jet CM1312nfi MFP: No compatible Twain installed device

    Hello I hope someone can help please. Yesterday, I was using my printer color Laser Jet CM1312nfi MFP multifunction scan a few pages. The analysis went through fine without problem like so many others before. No changes have been made to the system a