Error : CONNECT BY loop in user data

Getting CONNECT BY loop in user data:
Table X  (sample data actually have 35K rows)
CODE             CASE              OLD_ID                NEW_ID            PERSON       AUTH
01              ab122         1234               0001             AU123     99393
07              vv353          7872               0919             FV982     78282
01              ab122         1982               9929             AU123     99393
04               hjsss         8839                8302            JK920     32320
01              ab122         0001               1982             AU123     99393
05              cg899         6728               32322           IKL020     65252
07              w353          0919                8282             FV982     78282
now I need to order this data comparing row values of old_id to new_id for each of the combinations of code, person, case
need output like below
Table X
CODE             CASE              OLD_ID                NEW_ID            PERSON       AUTH
01              ab122         1234               0001             AU123     99393
01              ab122         0001               1982             AU123     99393
01              ab122         1982               9929             AU123     99393
04               hjsss         8839                8302            JK920     32320
05              cg899         6728              32322           IKL020     65252
07              vv353          7872               0919             FV982     78282
07              w353          0919                8282            FV982     78282
to get this I am using:
--Query--
select * from table_x
start with old_id not in(
                                  select new_id
                                  from table_x
CONNECT BY old_id = PRIOR new_id
       AND   code   = PRIOR code
       AND   case   = PRIOR case
       AND   person = PRIOR person
--Query--
runs fine with sample data but the problem is when excute it with actual table that has 35K records..
Cause: The condition specified in a CONNECT BY clause caused a loop in the query, where the next record to be selected is a descendent of itself. When this happens, there can be no end to the query.
Action: Check the CONNECT BY clause and remove the circular reference.
Thanks,
AK

Hi,
CONNECT_BY_ISCYCLE is a pseudo-column that you can use in a CONNECT BY NOCYCLE query.  It's separate from the CONNECT BY clause.
Try this:
select  code, "CASE", person
,       SYS_CONNECT_BY_PATH (old_id, '/') AS path
from    table_x
where   CONNECT_BY_ISCYCLE = 1
start with  old_id not in (
                                  select new_id
                                  from table_x
CONNECT BY NOCYCLE old_id = PRIOR new_id
        AND        code   = PRIOR code
        AND        "CASE" = PRIOR "CASE"
        AND        person = PRIOR person
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ: https://forums.oracle.com/message/9362002#9362002

Similar Messages

  • Getting "CONNECT BY loop in user data" error

    Hi all,
    I used to run the following query but I got this error "CONNECT BY loop in user data"
    select * from
    bom_details
    where common_bill_sequence_id=bill_sequence_id
    connect by prior assembly_item_id=component_item_id
    Bom_details is one view which contains
    SELECT distinct bi1.assembly_item_id, bic.bill_sequence_id, bi1.organization_id,
    bi1.common_bill_sequence_id, bic.component_item_id,
    bic.component_quantity, bic.item_num
    FROM bom_bill_of_materials bi1, bom_inventory_components bic
    where bi1.bill_sequence_id = bic.bill_sequence_id
    Please advice how to use the query.
    Thanks,
    Kamal

    Hi,
    You could try using the NOCYCLE directive to avoid user data errors e.g.
    select * from
    bom_details
    where common_bill_sequence_id=bill_sequence_id
    connect by NOCYCLE prior assembly_item_id=component_item_id
    Rod West

  • Error: ORA-01436: CONNECT BY loop in user data.... with EnableVersioning

    Hi everyone,
    i'm having some troubles when i execute DBMS_WM.EnableVersioning() procedure for all of the tables from my database.
    This is the sql line....
    EXEC DBMS_WM.EnableVersioning('SAN.SAN_AMPLIAC_ANULAC, SAN.SAN_ANALISISCALIDAD, SAN.SAN_ANALISISCALIDAD_LTS, SAN.SAN_ANALISISCALITEM, SAN.SAN_ANALISISCAMARA, SAN.SAN_APLICACION, SAN.SAN_APLICACION_ORDEN, SAN.SAN_APLI_ORD_ITEM', 'VIEW_WO_OVERWRITE');
    And the error is:
    ORA-01436: CONNECT BY loop in user data
    ORA-06512: at "SYS.LTDDL", line 1464
    ORA-06512: at "SYS.LTDDL", line 1289
    ORA-06512: at "SYS.LT", line 796
    ORA-06512: at "SYS.LT", line 8374
    ORA-06512: at line 2
    If somebody knows how to fix it, please let me know.
    Thanks in advance,
    Jime.

    Hello Ben!
    Thanks for answer me. I need to fix this as soon as possible.
    Thank you.
    Jime
    [email protected]
    Here are the answers to your questions:
    1. i'm using Oracle 9i
    2.
    NAME VALUE
    ALLOW_CAPTURE_EVENTS OFF
    ALLOW_MULTI_PARENT_WORKSPACES OFF
    ALLOW_NESTED_TABLE_COLUMNS OFF
    CR_WORKSPACE_MODE OPTIMISTIC_LOCKING
    FIRE_TRIGGERS_FOR_NONDML_EVENTS ON
    NONCR_WORKSPACE_MODE OPTIMISTIC_LOCKING
    OWM_VERSION 9.2.0.2.0
    USE_TIMESTAMP_TYPE_FOR_HISTORY ON
    3.
    OWNER CONSTRAINT_NAME CONSTRAINT_TYPE TABLE_NAME SEARCH_CONDITION R_OWNER R_CONSTRAINT_NAME DELETE_RULE STATUS DEFERRABLE DEFERRED VALIDATED GENERATED BAD RELY LAST_CHANGE INDEX_OWNER INDEX_NAME INVALID VIEW_RELATED
    SAN FK_ANALISISCALIDAD_1 R SAN_ANALISISCALIDAD SAN PK_SAN_GRADO CASCADE ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED USER NAME 9/22/2003 1:15:11 PM
    SAN FK_ANALISISCALITEM_1 R SAN_ANALISISCALITEM SAN PK_SAN_RUBRO CASCADE DISABLED NOT DEFERRABLE IMMEDIATE NOT VALIDATED USER NAME 9/22/2003 1:15:16 PM
    SAN FK_ANALISISCALITEM_2 R SAN_ANALISISCALITEM SAN PK_ID_SERVICIO CASCADE ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED USER NAME 9/22/2003 1:15:16 PM
    SAN FK_ANALISISCALITEM_3 R SAN_ANALISISCALITEM SAN PK_ANALISISCALIDAD CASCADE ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED USER NAME 9/22/2003 1:22:39 PM
    SAN FK_ANALISISCAMARA_1 R SAN_ANALISISCAMARA SAN PK_SAN_CLIENTE_PARTE_ROL CASCADE ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED USER NAME 9/22/2003 1:15:14 PM
    SAN FK_ANALISISCAMARA_2 R SAN_ANALISISCAMARA SAN PK_ANALISISCAMARA CASCADE ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED USER NAME 9/22/2003 1:22:21 PM
    SAN FK_ANALISISCAMARA_3 R SAN_ANALISISCAMARA SAN PK_ANALISISCALIDAD CASCADE ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED USER NAME 9/22/2003 1:22:21 PM
    SAN FK_SAN_APLICACION_ORDEN R SAN_APLI_ORD_ITEM SAN PK_SAN_APLICACION_ORDEN NO ACTION ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED USER NAME 6/19/2003 5:34:46 PM
    SAN FK_SAN_ORDEN_ITEMS R SAN_APLI_ORD_ITEM SAN PK_SAN_ORDEN_ITEMS NO ACTION ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED USER NAME 6/19/2003 5:34:48 PM
    SAN PK_ANALISISCALIDAD P SAN_ANALISISCALIDAD ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED USER NAME 9/22/2003 1:15:11 PM PK_ANALISISCALIDAD
    SAN PK_ANALISISCALITEM P SAN_ANALISISCALITEM ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED USER NAME 9/22/2003 1:15:16 PM PK_ANALISISCALITEM
    SAN PK_ANALISISCAMARA P SAN_ANALISISCAMARA ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED USER NAME 9/22/2003 1:15:13 PM PK_ANALISISCAMARA
    SAN PK_APLIC_ORDEN_ITEM P SAN_APLI_ORD_ITEM ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED USER NAME 6/19/2003 5:34:11 PM PK_APLIC_ORDEN_ITEM
    SAN PK_SAN_APLICACION_ORDEN P SAN_APLICACION_ORDEN ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED USER NAME 6/19/2003 5:34:20 PM PK_SAN_APLICACION_ORDEN
    SAN SYS_C0019582 C SAN_APLICACION_ORDEN "DENOMINACION" IS NOT NULL ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED GENERATED NAME 6/19/2003 5:08:54 PM
    SAN SYS_C0019586 C SAN_APLI_ORD_ITEM "ORDEN" IS NOT NULL ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED GENERATED NAME 6/19/2003 5:08:55 PM
    SAN SYS_C0019587 C SAN_APLI_ORD_ITEM "CONDICION" IS NOT NULL ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED GENERATED NAME 6/19/2003 5:08:55 PM
    SAN SYS_C0020519 C SAN_APLICACION_ORDEN "ID_APLICACION_ORDEN" IS NOT NULL ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED GENERATED NAME 6/19/2003 5:31:45 PM
    SAN SYS_C0020520 C SAN_APLI_ORD_ITEM "ID_APLICACION_ORDEN" IS NOT NULL ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED GENERATED NAME 6/19/2003 5:31:45 PM
    SAN SYS_C0020521 C SAN_APLI_ORD_ITEM "ID_APLI_ORD_ITEM" IS NOT NULL ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED GENERATED NAME 6/19/2003 5:31:45 PM
    SAN SYS_C0020522 C SAN_APLI_ORD_ITEM "ID_ITEM" IS NOT NULL ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED GENERATED NAME 6/19/2003 5:31:45 PM
    SAN SYS_C0021509 C SAN_ANALISISCALIDAD "ID_ANALISISCALIDAD" IS NOT NULL ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED GENERATED NAME 8/11/2003 6:42:52 PM
    SAN SYS_C0021512 C SAN_ANALISISCALITEM "ID_ANALISISCALITEM" IS NOT NULL ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED GENERATED NAME 8/11/2003 6:42:52 PM
    SAN SYS_C0021790 C SAN_ANALISISCAMARA "ID_ANALISISCALIDAD" IS NOT NULL ENABLED NOT DEFERRABLE IMMEDIATE VALIDATED GENERATED NAME 9/3/2003 1:09:39 PM
    4.
    OWNER CONSTRAINT_NAME TABLE_NAME COLUMN_NAME POSITION
    SAN FK_ANALISISCALIDAD_1 SAN_ANALISISCALIDAD ID_GRADO 1
    SAN FK_ANALISISCALITEM_1 SAN_ANALISISCALITEM ID_RUBRO 1
    SAN FK_ANALISISCALITEM_2 SAN_ANALISISCALITEM ID_SERVICIO 1
    SAN FK_ANALISISCALITEM_3 SAN_ANALISISCALITEM ID_ANALISISCALIDAD 1
    SAN FK_ANALISISCAMARA_1 SAN_ANALISISCAMARA ID_CLIENTEPARTEROL 1
    SAN FK_ANALISISCAMARA_2 SAN_ANALISISCAMARA ID_ANALISISCALIDAD 1
    SAN FK_ANALISISCAMARA_3 SAN_ANALISISCAMARA ID_ANALISISCALIDAD 1
    SAN FK_SAN_APLICACION_ORDEN SAN_APLI_ORD_ITEM ID_APLICACION_ORDEN 1
    SAN FK_SAN_ORDEN_ITEMS SAN_APLI_ORD_ITEM ID_ITEM 1
    SAN PK_ANALISISCALIDAD SAN_ANALISISCALIDAD ID_ANALISISCALIDAD 1
    SAN PK_ANALISISCALITEM SAN_ANALISISCALITEM ID_ANALISISCALITEM 1
    SAN PK_ANALISISCAMARA SAN_ANALISISCAMARA ID_ANALISISCALIDAD 1
    SAN PK_APLIC_ORDEN_ITEM SAN_APLI_ORD_ITEM ID_APLI_ORD_ITEM 1
    SAN PK_SAN_APLICACION_ORDEN SAN_APLICACION_ORDEN ID_APLICACION_ORDEN 1
    SAN SYS_C0019582 SAN_APLICACION_ORDEN DENOMINACION
    SAN SYS_C0019586 SAN_APLI_ORD_ITEM ORDEN
    SAN SYS_C0019587 SAN_APLI_ORD_ITEM CONDICION
    SAN SYS_C0020519 SAN_APLICACION_ORDEN ID_APLICACION_ORDEN
    SAN SYS_C0020520 SAN_APLI_ORD_ITEM ID_APLICACION_ORDEN
    SAN SYS_C0020521 SAN_APLI_ORD_ITEM ID_APLI_ORD_ITEM
    SAN SYS_C0020522 SAN_APLI_ORD_ITEM ID_ITEM
    SAN SYS_C0021509 SAN_ANALISISCALIDAD ID_ANALISISCALIDAD
    SAN SYS_C0021512 SAN_ANALISISCALITEM ID_ANALISISCALITEM
    SAN SYS_C0021790 SAN_ANALISISCAMARA ID_ANALISISCALIDAD

  • How to bypass "ORA-01436: CONNECT BY loop in user data" ?

    Hello everybody
    I have a problem with a ORA-01436 firing too early on a query I'm trying to execute.
    There is a table of strings. Each string on that table should be composed of a single character or it must be obtained by the concatenation of a single character on another string in the table.
    Sometime this requirement is missing. I can't do anything to drive the table to be in that way. So I would like to execute a query witch corrects that table by adding the missing strings in it. When there are some strings that can't be obtained by appending a single char from another string the the query should list also the missing chain of strings to make that string valid in the table.
    An example.
    create table strings (
         val varchar2(10) not null
    insert into strings (val) values ('A')
    insert into strings (val) values ('ABCDE')
    insert into strings (val) values ('AD')
    insert into strings (val) values ('ADF')
    select *
    from strings
    order by val
    Query finished, retrieving results...
        VAL   
    A         
    ABCDE     
    AD        
    ADF       
    4 row(s) retrievedAs you can see the bold string ABCDE is not valid because it can't be obtained by
    appending a single char to any other string in the table.
    In this case a valid result should also list the chain of strings 'AB', 'ABC' and 'ABCD'.
    To find the strings where a chain of missing strings begins and finishes I use this query.
    Processing ...
    select val,p_val
    from (
         select val,lag(val) over (order by val) as p_val
         from strings
    ) a
    WHERE val not like p_val||'_' and val like p_val||'%' AND p_val IS NOT NULL
    Query finished, retrieving results...
        VAL       P_VAL  
    ABCDE      A         
    1 row(s) retrievedIn this simple case a can list the missing strings with this query.
    Processing ...
    select val,p_val,p_val||SUBSTR(val,LENGTH(p_val)+1,LEVEL) as chain_string,LEVEL
    FROM (
    select val,p_val
    from (
         select val,lag(val) over (order by val) as p_val
         from strings
    ) a
    WHERE val not like p_val||'_' and val like p_val||'%' AND p_val IS NOT NULL
    CONNECT BY LENGTH(val)>LENGTH(p_val)+LEVEL
    Query finished, retrieving results...
        VAL       P_VAL       CHAIN_STRING                      LEVEL                
    ABCDE      A          AB                                                        1
    ABCDE      A          ABC                                                       2
    ABCDE      A          ABCD                                                      3
    3 row(s) retrievedBut when I have more than one string to be validated things change and the hierarchical query is not good any more in this way.
    insert into strings (val) values ('ADFGH')
    Processing ...
    select *
    from strings
    order by val
    Query finished, retrieving results...
        VAL   
    A         
    ABCDE     
    AD        
    ADF       
    ADFGH     
    5 row(s) retrievedBecause I retrieve solutions regarding the one string mixed with all the others
    Processing ...
    select val,p_val,p_val||SUBSTR(val,LENGTH(p_val)+1,LEVEL) as chain_string,LEVEL
    FROM (
    select val,p_val
    from (
         select val,lag(val) over (order by val) as p_val
         from strings
    ) a
    WHERE val not like p_val||'_' and val like p_val||'%' AND p_val IS NOT NULL
    CONNECT BY LENGTH(val)>LENGTH(p_val)+LEVEL
    Query finished, retrieving results...
        VAL       P_VAL       CHAIN_STRING                      LEVEL                
    ABCDE      A          AB                                                        1
    ABCDE      A          ABC                                                       2
    ABCDE      A          ABCD                                                      3
    ADFGH      ADF        ADFG                                                      1
    ABCDE A ABC 2
    ABCDE A ABCD 3
    6 row(s) retrievedTo avoid this I should add a condition to link val to prior val in the connect by clause but here it throws ORA-01436.
    Processing ...
    select val,p_val,p_val||SUBSTR(val,LENGTH(p_val)+1,LEVEL) as chain_string,LEVEL
    FROM (
    select val,p_val
    from (
         select val,lag(val) over (order by val) as p_val
         from strings
    ) a
    WHERE val not like p_val||'_' and val like p_val||'%' AND p_val IS NOT NULL
    CONNECT BY LENGTH(val)>LENGTH(p_val)+LEVEL AND val = PRIOR val
    select val,p_val,p_val||SUBSTR(val,LENGTH(p_val)+1,LEVEL) as chain_string,LEVEL
    ORA-01436: CONNECT BY loop in user dataWhat could I do to bypass that check?
    I know I could query for distinct values on the first query (the one without the condition val = PRIOR val ) but I'd like to know if you had similar problems and how did you solved them in this case.
    Thanks
    Bye Alessandro

    I don't know why but with 10.2.0.4 Oracle now found a way to raise this error again.
    Connected to:                                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production          
    With the Partitioning, Real Application Clusters, OLAP, Data Mining                   
    and Real Application Testing options                                                  
    SQL> create table strings (                                                        
      2     val varchar2(10) not null                                                     
      3  )                                                                                
      4  /                                                                                
    Table created.                                                                        
    SQL>                                                                               
    SQL> insert into strings (val) values ('A')                                        
      2  /                                                                                
    1 row created.                                                                        
    SQL> insert into strings (val) values ('ABCDE')                                    
      2  /                                                                                
    1 row created.                                                                        
    SQL> insert into strings (val) values ('AD')                                       
      2  /                                                                                
    1 row created.                                                                        
    SQL> insert into strings (val) values ('ADF')                                      
      2  /                                                                                
    1 row created.                                                                        
    SQL>                                                                               
    SQL> select val,p_val,p_val||SUBSTR(val,LENGTH(p_val)+1,LEVEL) as chain_string,LEVEL
      2  FROM (select val,p_val                                                           
      3        from (                                                                     
      4              select val,lag(val) over (order by val) as p_val                     
      5              from strings) a                                                      
      6        WHERE val not like p_val||'_' and val like p_val||'%' AND p_val IS NOT NULL)
      7  CONNECT BY LENGTH(val)>LENGTH(p_val)+LEVEL  AND val = PRIOR val                  
      8  and prior dbms_random.value is not null                                          
      9  /                                                                                
    ERROR:                                                                                
    ORA-01436: CONNECT BY loop in user data                                               
    no rows selected                                                                      
    SQL>Had someone of you found a way to do it again.
    Thanks
    Bye Alessandro

  • Need help in resolving CONNECT BY loop in user data in Oracle 9.2.0.5 Ver

    Hi Everyone,
    Below are the scripts to reproduce the error
    CREATE TABLE TESTING
    C1 NUMBER,
    C2 NUMBER,
    GRP NUMBER
    Insert into TESTING
    (C1, C2, GRP)
    Values
    (1, 2, 100);
    Insert into TESTING
    (C1, C2, GRP)
    Values
    (1, 3, 100);
    Insert into TESTING
    (C1, C2, GRP)
    Values
    (2, 5, 200);
    Insert into TESTING
    (C1, C2, GRP)
    Values
    (3, 11, 200);
    Insert into TESTING
    (C1, C2, GRP)
    Values
    (11, 1, 400);
    COMMIT;
    SELECT sys_connect_by_path(C1,'/') AS C1,C2
    FROM TESTING
    CONNECT BY C1 = PRIOR C2
    I am getting "ORA-01436: CONNECT BY loop in user data" because of Recurssion.
    My Oracle Version is 9.2.0.5, can you guide me how to resolve in 9.2.0.5
    In Oracle 10g I have read that we can achieve through NOCYCLE option
    Can you please guide me how to solve this in Oracle 9.2.0.5 Version
    Thanks in Advance,
    Sankar

    SQL> SELECT     SYS_CONNECT_BY_PATH (c1, '/') AS c1, c2
      2        FROM testing
      3  CONNECT BY  c1 = PRIOR c2 AND (c2 >= PRIOR c1);
    C1                                                         C2
    /1                                                          2
    /1/2                                                        5
    /1                                                          3
    /1/3                                                       11
    /2                                                          5
    /3                                                         11
    /11                                                         1
    7 ligne(s) sélectionnée(s).
    SQL>

  • DBMS_RANDOM and ORA-01436: CONNECT BY loop in user data

    Hi,
    The following query gets the error "ORA_01436: CONNECT BY loop in user data":
    SELECT     currentdate
    ,     ADD_MONTHS ( currentdate
                 , (LEVEL - 1) * months
                 ) + ((LEVEL - 1) * days)     AS final_date
    ,     level
    FROM     table_z
    WHERE     CONNECT_BY_ISLEAF = 1
    CONNECT BY     currentdate               = PRIOR currentdate
    AND          PRIOR dbms_random.value          IS NOT NULL
    AND          ADD_MONTHS ( currentdate
                         , (LEVEL - 2) * months
                         ) + ((LEVEL - 2) * days) <= TO_DATE ( '05/01/2008'
                                                                      , 'MM/DD/YYYY'
                                                  );I've seen "PRIOR dbms_random.value IS NOT NULL" used like this as as a way to get around ORA-01436 in Oracle 9, but I'm using Oracle 11, and it doesn't work
    currentdate is unique.
    If I hard-code any one set of values, like this:
    DEFINE currentdate      = "TO_DATE ('03/02/2006', 'MM/DD/YYYY')"
    DEFINE days           = 300
    DEFINE months           = 0
    SELECT     &currentdate
    ,     ADD_MONTHS ( &currentdate
                 , (LEVEL - 1) * &months
                 ) + ((LEVEL - 1) * &days)     AS final_date
    FROM     dual
    WHERE     CONNECT_BY_ISLEAF = 1
    CONNECT BY     &currentdate               = PRIOR &currentdate
    AND          PRIOR dbms_random.value          IS NOT NULL
    AND          ADD_MONTHS ( &currentdate
                         , (LEVEL - 2) * &months
                         ) + ((LEVEL - 2) * &days) <= TO_DATE ( '05/01/2008'
                                                                       , 'MM/DD/YYYY'
                                                   );I can get the correct results from dual. I was looking for a way to extend this to get multiple rows from table_z in the same query.
    The problem came up in [this thread|http://forums.oracle.com/forums/thread.jspa?threadID=894946&tstart=0], where the problem is:
    Given this table:
    CREATE TABLE     table_z
    (      currentdate     DATE
    ,      months          NUMBER
    ,      days          NUMBER
    INSERT INTO table_z (currentdate, months, days) VALUES (TO_DATE ('03/02/2006', 'MM/DD/YYYY'),     0,     300);
    INSERT INTO table_z (currentdate, months, days) VALUES (TO_DATE ('04/05/2006', 'MM/DD/YYYY'),     10,     0);
    INSERT INTO table_z (currentdate, months, days) VALUES (TO_DATE ('05/04/2006', 'MM/DD/YYYY'),     3,     0);I'm trying to add the given number of months and/or days to currentdate until I reach a given hard-coded cutoff date (05/01/2008 in this case).
    That is, the desired results from the data above are:
    CURRENTDAT     MONTHS       DAYS FINALDATE
    03/02/2006          0        300 08/18/2008
    04/05/2006         10          0 10/05/2008
    05/04/2006          3          0 05/04/2008Edited by: Frank Kulash on May 4, 2009 7:38 PM
    Typo in CONNECT BY conditions fixed.

    Hi Frank,
    Sounds like a bug. Funny enough, but this works:
    SQL> select * from v$version where rownum = 1
      2  /
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
    SQL> SELECT currentdate
      2  , ADD_MONTHS ( currentdate
      3       , (LEVEL - 1) * months
      4       ) + ((LEVEL - 1) * days) AS final_date
      5  , level
      6  FROM table_z
      7  WHERE CONNECT_BY_ISLEAF = 1
      8  CONNECT BY currentdate   = PRIOR currentdate
      9  AND  PRIOR dbms_random.value  IS NOT NULL
    10  AND  ADD_MONTHS ( currentdate
    11           , (LEVEL - 1) * months
    12           ) + ((LEVEL - 1) * days) <= TO_DATE ( '05/01/2008'
    13                                        , 'MM/DD/YYYY'
    14                    );
    FROM table_z
    ERROR at line 6:
    ORA-01436: CONNECT BY loop in user data
    SQL>
    SQL> ed
    Wrote file afiedt.buf
      1  SELECT currentdate
      2  , ADD_MONTHS ( currentdate
      3       , (LEVEL - 1) * months
      4       ) + ((LEVEL - 1) * days) AS final_date
      5  , level
      6  FROM table_z
      7  WHERE CONNECT_BY_ISLEAF = 1
      8  CONNECT BY currentdate   = PRIOR currentdate + 0
      9  AND  PRIOR dbms_random.value  IS NOT NULL
    10  AND  ADD_MONTHS ( currentdate
    11           , (LEVEL - 1) * months
    12           ) + ((LEVEL - 1) * days) <= TO_DATE ( '05/01/2008'
    13                                        , 'MM/DD/YYYY'
    14*                   )
    SQL> /
    CURRENTDA FINAL_DAT      LEVEL
    02-MAR-06 23-OCT-07          3
    05-APR-06 05-DEC-07          3
    04-MAY-06 04-FEB-08          8
    SQL> SY.

  • ORA-01436: CONNECT BY loop in user data

    We are using Oracle HR Manager Self Service and using the menu option, Worker Status Change, the subject error message appears when an attempt is made to submitted for approval.
    Any suggestions as to what could be causing this?
    Thanks,
    Lee

    Please post the details of the application release, database version and OS.
    We are using Oracle HR Manager Self Service and using the menu option, Worker Status Change, the subject error message appears when an attempt is made to submitted for approval.
    Any suggestions as to what could be causing this?Please review these docs and see if it helps.
    SSHR - ORA-01436 Connect By Loop Error In User Data In Manager Self Service [ID 333630.1]
    PER_449800_ORA_1436 When Clicking On Manager Actions Links [ID 427428.1]
    Ora-01436: Connect By Loop In User Data Ora-06512: At "Apps.Hr_security_internal [ID 873617.1]
    ORA-01436: CONNECT BY LOOP in user data in SSHR [ID 275819.1]
    SSHR: ORA-01436: Connect By Loop In User Data [ID 357718.1]
    Configuring Oracle Self-Service Human Resources (SSHR) Approvals Using Approvals Management (AME) [ID 360515.1]
    Thanks,
    Hussein

  • ORA-01436: CONNECT BY loop in user data, but CONNECT_BY_ISCYCLE is all ZERO

    hi,
    when I run below query, it always throws error below:
    SELECT connect_by_root code AS code_root,
        CODE,
        CODE_DESC,
        UP_CODE
      FROM DI_CODE_LEVEL
      WHERE TYPE_CODE='SP'
        CONNECT BY PRIOR CODE=UP_CODE;
    ORA-01436: CONNECT BY loop in user data
    01436. 00000 -  "CONNECT BY loop in user data"But when I use NOCLYCLE and CONNECT_BY_ISCYCLE to find out which row is in question,
    it shows nothing, which means CONNECT_BY_ISCYCLE=ZERO for all rows.
    select * from (
        SELECT connect_by_root code AS code_root,
            CODE,
            CODE_DESC,
            UP_CODE ,
            CONNECT_BY_ISCYCLE AS ISCYCLE
          FROM DI_CODE_LEVEL
          WHERE TYPE_CODE='SP'
            CONNECT BY NOCYCLE PRIOR CODE=UP_CODE
    where ISCYCLE>0;Is there any other reason that this sql would throw ORA-01436?
    If there is a loop, then will the combination of NOCYCLE, CONNECT_BY_ISCYCLE will show?
    Thanks

    Hi,
    Apparantly, one or more of the 'SP' rows are causing the problem.
    The WHERE clause is applied after the CONNECT BY is finished, so saying:
    select * from (
        SELECT connect_by_root code AS code_root,
            CODE,
            CODE_DESC,
            UP_CODE ,
            CONNECT_BY_ISCYCLE AS ISCYCLE
          FROM DI_CODE_LEVEL
          WHERE TYPE_CODE='SP'
            CONNECT BY NOCYCLE PRIOR CODE=UP_CODE
    where ISCYCLE>0;is equivalent to
    select * from (
        SELECT connect_by_root code AS code_root,
            CODE,
            CODE_DESC,
            UP_CODE ,
            CONNECT_BY_ISCYCLE AS ISCYCLE
          FROM DI_CODE_LEVEL
            CONNECT BY NOCYCLE PRIOR CODE=UP_CODE
    WHERE    TYPE_CODE = 'SP'
    AND     ISCYCLE   > 0;To see where the loop occurs, you have to include the rows where type_code='SP'.
    When debugging "ORA-01436: CONNECT BY loop in user data", display SYS_CONNECT_BY_PATH (uk, ...), where uk is some unique key. That will tell you a lot more than just the root information. You might want this:
    SELECT  connect_by_root code                AS code_root,
            CODE,
            CODE_DESC,
            UP_CODE
    ,     SYS_CONNECCT_BY_PATH (code, '/')     AS path          -- For debugging
    ,       CONNECT_BY_ISCYCLE                AS ISCYCLE     -- For debugging
    FROM      DI_CODE_LEVEL
    -- WHERE TYPE_CODE = 'SP'     -- Commented out for debugging
    where      ISCYCLE > 0          -- For debugging
    CONNECT BY NOCYCLE      PRIOR CODE = UP_CODE 
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data.
    Explain how you get those results from that data.
    Always say what version of Oracle you're using.

  • ORA-01436 CONNECT by loop in user data Oracle HRMS - How do I prevent this?

    I am getting from time to time an error when users are performing tasks in Oracle HRMS that comes back as ORA-01436 CONNECT by loop in user data.
    This issue is caused when there exists a loop in the Supervisor hierarchy.
    For ex: Emp A reports to Emp B and Emp B reports to A
    OR
    Emp A reports to B and B reports to C and C reports to A.
    It can be any of the above or if there are more approvers then there can be a
    bigger loop.
    This is described on Oracle Metalink Doc ID: 275819.1
    This happens to us regularly; someone puts the manager of an employee as the subordinate of the 1st employee - of course this is not logically possible!
    My question is how do i prevent this in the HRMS Manager tool or the Self Service functionality - I want the user to be informed and prevented from creating these infinite loops in the first place ...any ideas?

    Hi,
    We suffer same the kind of issue but as you might have seen there is no immediate answer from Oracle about implementing a check within the Application forms/SS. In the end we wrote a report to hunt to locate loops in employee supervisor chain and report any circular references it finds. This report is scheduled to run every day and the customer reviews the output and then fixes the loops. Not ideal but we've not had chance to investigate a custom trigger say on the per_all_assignments_f table.

  • CONNECT BY loop in user data

    Hi everbody,
    Please a need some help with this:
    I'm learning about how to generate rows in oracle from the page.
    http://blog.lishman.com/2008/02/how-to-generate-rows-in-oracle_2477.html
    In that page there is an example like this:
    SELECT rownum
    FROM dual
    CONNECT BY LEVEL <= 5;
    I execute this sentence in my oracle 8i database but a get this message: CONNECT BY loop in user data
    Please,where is the problem?
    Thanks in advance

    user491853 wrote:
    Thank you justin !
    I need to execute this query, because I need to find what 'TUESDAYS' are between 2 dates:
    SELECT t.dt, TRIM (TO_CHAR (t.dt, 'DAY')) "DAY"
    FROM (SELECT TRUNC (SYSDATE) + ROWNUM dt
    FROM DUAL
    CONNECT BY LEVEL <= 80) t
    WHERE TRIM (TO_CHAR (t.dt, 'DAY')) = 'THURSDAY'
    AND t.dt BETWEEN TO_DATE ('01/08/2006', 'dd/mm/rrrr')
    AND TO_DATE ('31/08/2006', 'dd/mm/rrrr')
    The result would be:
    DT DAY
    03-AUG-06 THURSDAY
    10-AUG-06 THURSDAY
    17-AUG-06 THURSDAY
    24-AUG-06 THURSDAY
    31-AUG-06 THURSDAY
    How can I execute a similar query in oracle 8i? Thanks buddy for any response.I can't test it as I don't have access to 8i but does following query work (to generate rows)?
    SELECT  level
    FROM DUAL
    CONNECT BY LEVEL <= 80
    AND PRIOR dbms_random.random IS NOT NULL ;

  • Connect by loop in user data: urgent solution needed

    Hai iam using oracle9i and my problem is
    in my client place we r developing a report
    of bill_of_materials and it seems the data
    is having some recursive nature.
    iam getting connect by loop in user data: how to avoid it in oracle9i.
    i have two tables prm010ebomh1 and prm010ebomh2.
    now 1st table consists of the product and 2nd table consists of the components
    forming the product.
    a good solution is welcomed.
    My query is:
    SELECT DISTINCT B.SL_NO,A.FITEM_CD,B.SITEM_CD,
    LPAD(C.ITEM_DESC,LENGTH(C.ITEM_DESC)+(LEVEL*2)-2,' ') AssyLevel,
    b.qty
    from prm010ebomh a, prm010ebomd b,m032item c
    where a.fitem_cd=b.fitem_cd
    and a.type=b.type
    and a.comp_cd=b.comp_cd
    and a.comp_cdch=b.comp_cdch
    and a.comp_cd='IFA'
    AND A.COMP_CDCH='D01'
    START WITH A.FITEM_CD='A0150100'
    CONNECT BY A.FITEM_CD=PRIOR B.SITEM_CD
    ORDER SIBLINGS BY B.SL_NO.

    Modify the data so that the circular references are avoided.
    ORA-01436 CONNECT BY loop in user data
    Cause: The condition specified in a CONNECT BY clause caused a loop in the query, where the next record to be selected is a descendent of itself. When this happens, there can be no end to the query.
    Action: Check the CONNECT BY clause and remove the circular reference.

  • Hi,getting an error-ORA-01436: CONNECT BY loop in user data

    hi,i am getting an error while running the select query
    SELECT callreleasetime,calleventduration
    FROM temp_med_partial_records_0001
    CONNECT BY PRIOR callreleasetime=callreleasetime
    AND PRIOR IMSI=IMSI
    AND PRIOR connectedcallingnumber=connectedcallingnumber
    Edited by: user8731258 on Feb 8, 2011 2:34 AM

    example:
    drop table test;
    create table test(no number, IMSP number,  IMSC number,  data varchar2(10));
    insert into test values(1,1,2,'a');
    insert into test values(1,2,3,'a');
    insert into test values(1,2,4,'a');
    insert into test values(1,3,5,'b');
    insert into test values(1,4,5,'b');
    insert into test values(2,1,2,'c');
    insert into test values(2,2,3,'c');
    insert into test values(4,1,2,'d');
    insert into test values(4,2,3,'d');
    insert into test values(5,1,2,'e');
    insert into test values(5,2,3,'e');
    insert into test values(5,2,3,'e');
    insert into test values(6,1,2,'f');
    commit;
    SELECT *
    FROM test
    CONNECT BY PRIOR no=no
    AND PRIOR IMSP=IMSC
    AND PRIOR data=data;
    NO                     IMSP                   IMSC                   DATA      
    1                      1                      2                      a         
    1                      2                      3                      a         
    1                      1                      2                      a         
    1                      2                      4                      a         
    1                      1                      2                      a         
    1                      3                      5                      b         
    1                      4                      5                      b         
    2                      1                      2                      c         
    2                      2                      3                      c         
    2                      1                      2                      c         
    4                      1                      2                      d         
    4                      2                      3                      d         
    4                      1                      2                      d         
    5                      1                      2                      e         
    5                      2                      3                      e         
    5                      1                      2                      e         
    5                      2                      3                      e         
    5                      1                      2                      e         
    6                      1                      2                      f   Your case
    SELECT *
    FROM test
    CONNECT BY PRIOR no=no
    AND PRIOR IMSP=IMSP
    AND PRIOR data=data;
    ORA-01436:

  • Error  ORA-01436: CONNECT BY loop in user data

    Y is it failing , when the query with test data is working fine. Added the output of individual queries from data base.
    some times parent_order and order can be same.
    SELECT *
      FROM (SELECT     *
                  FROM r_brj_linkage
            START WITH order_id = 'IQBGSR20'
            CONNECT BY PRIOR parent_downstream_orderid = order_id)
    WHERE alternate_linkage_rule_flag = 'N'
    SELECT parent_downstream_orderid, order_id, alternate_linkage_rule_flag
      FROM r_brj_linkage
    WHERE order_id = 'IQBGSR20';
    output
    U206650.3     IQBGSR20   Y
    SELECT parent_downstream_orderid, order_id, alternate_linkage_rule_flag
      FROM r_brj_linkage
    WHERE order_id = 'U206650.3';
    U206650.3      U206650.3  Ni tried it with an example , and its giving me the correct results
    SELECT *
      FROM (WITH t AS
                 (SELECT 'XXX' parent_1, 'YYY' child_1, 'Y' flag
                    FROM DUAL
                  UNION ALL
                  SELECT 'XYZ' AS parent_1, 'XXX' AS child_1, 'Y' AS flag
                    FROM DUAL
                  UNION ALL
                  SELECT 'ZZZ' AS parent_1, 'XYZ' AS child_1, 'Y' AS flag
                    FROM DUAL
                  UNION ALL
                  SELECT 'ABC' AS parent_1, 'ZZZ' AS child_1, 'N' AS flag
                    FROM DUAL)
            SELECT     *
                  FROM t
            START WITH child_1 = 'ZZZ'
            CONNECT BY PRIOR parent_1 = child_1)
    WHERE flag = 'N';Edited by: devarade on Jan 21, 2010 2:56 PM
    Edited by: devarade on Jan 21, 2010 3:06 PM

    i posted the output from individual select queries. its like the last record is reporting to itself. 'ZZZ' is reporting to 'ZZZ'
    this is the replecated data, when i use nocycle it is returning no data
    SELECT *
      FROM (WITH t AS
                 (SELECT 'XXX' parent_1, 'YYY' child_1, 'Y' flag
                    FROM DUAL
                  UNION ALL
                  SELECT 'XYZ' AS parent_1, 'XXX' AS child_1, 'Y' AS flag
                    FROM DUAL
                  UNION ALL
                  SELECT 'ZZZ' AS parent_1, 'XYZ' AS child_1, 'Y' AS flag
                    FROM DUAL
                  UNION ALL
                  SELECT 'ZZZ' AS parent_1, 'ZZZ' AS child_1, 'N' AS flag
                    FROM DUAL)
            SELECT     *
                  FROM t
            START WITH child_1 = 'YYY'
            CONNECT BY NOCYCLE PRIOR parent_1 = child_1)
    WHERE flag = 'N';Edited by: devarade on Jan 21, 2010 3:30 PM
    Edited by: devarade on Jan 21, 2010 3:30 PM

  • Heirarchical Query, Connect By Loop in User Data

    Hi,
    Is there any method to find the node which has problem in heirachical query.
    As my data is complex and has levels upto 10 , its not possbile to fix manually. I have idendtified the series "START WITH" ,which causing problem. But I couldnt find the exact nodes in the seris which creates the loop.
    Even exception handling not working in that.
    Please advice.
    Regards,
    Benz

    Thanks Padders,
    This helped me to skip the coonect by Loop error.
    I was using 10.2.0.3
    Regards,
    Benz

  • How Can I to prevent == ORA-01436: CONNECT BY loop in user data

    Hi
    In query below
    WITH TT AS (SELECT '2' PAI, '3' FILHO FROM DUAL
                UNION ALL
                SELECT '3', '5'  FROM DUAL
                UNION ALL
                SELECT '3' ,'6' FROM DUAL
                union all
                select '3','4' from dual
                union all
                select '2' , '4' from dual
                union all
                select '2', '7' from dual
                union all
                select '4','8' from dual
                union all
                select '4', '9' from dual
                union all
                select '4', '10' from dual
                union all
                select '8','11' from dual
                union all
                select '8', '12' from dual
                union all
                select '11', '15' from dual
                union all
                select '8', '16' from dual
               union all
               select '9', '3' from dual)
       select distinct  pai, filho, level
       FROM TT   
       start with pai = &x        
       connect by prior filho = pai
       order by level  desc How can I to prevent error when user type the number 3 ?
    Message was edited by:
    muttleychess

    Hi , Tks
    work Fine
    WITH TT AS (SELECT '2' PAI, '3' FILHO FROM DUAL
                UNION ALL
                SELECT '3', '5'  FROM DUAL
                UNION ALL
                SELECT '3' ,'6' FROM DUAL
                union all
                select '3','4' from dual
                union all
                select '2' , '4' from dual
                union all
                select '2', '7' from dual
                union all
                select '4','8' from dual
                union all
                select '4', '9' from dual
                union all
                select '4', '10' from dual
                union all
                select '8','11' from dual
                union all
                select '8', '12' from dual
                union all
                select '11', '15' from dual
                union all
                select '8', '16' from dual
               union all
               select '9', '3' from dual
                union all
               select '11', '2' from dual
                union all
               select '11', '19' from dual
                union all
               select '19', '17' from dual
                union all
               select '17', '9' from dual)
       select distinct  pai, filho, level
       FROM TT   
       start with pai = &x        
       connect by prior filho = pai
       and mytree.connect_by_path(level,to_char(pai))||'/' not like '%'||to_char(prior pai)||'/%'
      order by 1,3But how can put in Order where show me all path , after other : Example begin with level 1 --> go to level 2 --> level 3....etc, after go other level 1, level 2 ...etc

Maybe you are looking for