Problem strange perf on hierarchical query

Hi gurus,

I have a problem of strange performance on a recursive query. By removing items one by one, I got the query begins to run very slowly when I add a GOLD in the CONNECT BY clause.

The simplified query is the following:

 SELECT
      CONNECT_BY_ROOT( a.c_individu )
     ,a.c_individu
     ,SYS_CONNECT_BY_PATH( to_char(a.c_individu,'FM099999999'), ' ') path
     ,LEVEL
   FROM
     aaa a
   WHERE 
         CONNECT_BY_ISLEAF=1
     AND LEVEL > 1
   CONNECT BY a.c_individu < PRIOR a.c_individu
                      AND ( a.prenom_norm= PRIOR a.prenom_norm
                            AND a.d_naissance = PRIOR a.d_naissance
                            AND a.nom_famille_norm = PRIOR a.nom_famille_norm
                         /* OR 1=2 */ )

AAA table contains 10,000 lines for my testing purposes and has an index on C_INDIVIDU.

If I run this query with the 'OR 1 = 2' commented, it runs pretty fast:

Elapsed: 00:00:00.10


Execution Plan
----------------------------------------------------------
Plan hash value: 3286454403


--------------------------------------------------------------------------------------
| Id  | Operation                     | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT              |      | 10000 |   292K|   578   (1)| 00:00:07 |
|*  1 |  FILTER                       |      |       |       |            |          |
|*  2 |   CONNECT BY WITHOUT FILTERING|      |       |       |            |          |
|   3 |    TABLE ACCESS FULL          | AAA  | 10000 |   292K|   578   (1)| 00:00:07 |
--------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


   1 - filter(CONNECT_BY_ISLEAF=1 AND LEVEL>1)
   2 - access("A"."PRENOM_NORM"=PRIOR "A"."PRENOM_NORM" AND
              "A"."D_NAISSANCE"=PRIOR "A"."D_NAISSANCE" AND "A"."NOM_FAMILLE_NORM"=PRIOR
              "A"."NOM_FAMILLE_NORM")
       filter("A"."C_INDIVIDU"<PRIOR "A"."C_INDIVIDU")

As soon as I add the 'OR 1 = 2' statement, the query runs very slowly (19 seconds vs 0.1 seconds) and the execution plan is very different:

Elapsed: 00:00:18.84


Execution Plan
----------------------------------------------------------
Plan hash value: 3286454403


--------------------------------------------------------------------------------------
| Id  | Operation                     | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT              |      | 10000 |   292K|   578   (1)| 00:00:07 |
|*  1 |  FILTER                       |      |       |       |            |          |
|*  2 |   CONNECT BY WITHOUT FILTERING|      |       |       |            |          |
|   3 |    TABLE ACCESS FULL          | AAA  | 10000 |   292K|   578   (1)| 00:00:07 |
--------------------------------------------------------------------------------------


Predicate Information (identified by operation id):
---------------------------------------------------


   1 - filter(CONNECT_BY_ISLEAF=1 AND LEVEL>1)
   2 - access(INTERNAL_FUNCTION("A"."C_INDIVIDU")<INTERNAL_FUNCTION(PRIOR
              "A"."C_INDIVIDU"))
       filter("A"."PRENOM_NORM"=PRIOR "A"."PRENOM_NORM" AND
              "A"."D_NAISSANCE"=PRIOR "A"."D_NAISSANCE" AND "A"."NOM_FAMILLE_NORM"=PRIOR
              "A"."NOM_FAMILLE_NORM" OR 1=2)

Could someone explain to me why?

Thank you!

BANNER
------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE    11.2.0.3.0      Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production

If the difference in the execution plan turning access predicates in the filter predicate will slow down performance as Oracle is looking more lines of analysis before filtering every time.

The reason why he chose to do this is because he can not use your predicates connect more to make a hash map of your table based on the predicates. When just using pure equality filters, Oracle managed to the hash table on

PRENOM_NORM, D_NAISSANCE, NOM_FAMILLE_NORM

You need put somehow your new expression on a equal footing, I did the below but it starts from the principle that no line of aaa have nom_famille_norm = ' #', you may need to fiddle.

SELECT
   CONNECT_BY_ROOT( a.c_individu )
  ,a.c_individu
  ,SYS_CONNECT_BY_PATH( to_char(a.c_individu,'FM099999999'), ' ') path
  ,LEVEL
FROM
  aaa a
WHERE
      CONNECT_BY_ISLEAF=1
  AND LEVEL > 1
CONNECT BY a.c_individu < PRIOR a.c_individu
                   AND ( a.prenom_norm= PRIOR a.prenom_norm
                         AND a.d_naissance = PRIOR a.d_naissance
                         AND CASE WHEN 1=2 THEN '##' ELSE a.nom_famille_norm END = CASE WHEN 1=2 THEN '##' ELSE PRIOR a.nom_famille_norm  END
                       )
/

--------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT |      |     1.  1219.     2 (0) | 00:00:01 |
|*  1 |  FILTER                       |      |       |       |            |          |
|*  2 |   CONNECT TO WITHOUT FILTERING.      |       |       |            |          |
|   3.    TABLE ACCESS FULL | AAA |     1.  1219.     2 (0) | 00:00:01 |
--------------------------------------------------------------------------------------

Information of predicates (identified by the operation identity card):
---------------------------------------------------

1 - filter(CONNECT_BY_ISLEAF=1 AND LEVEL>1)
2 - access("A".") PRENOM_NORM "="A"PRECONDITION." PRENOM_NORM' AND
"A"." D_NAISSANCE "="A"PRECONDITION." D_NAISSANCE' AND 'A '. "NOM_FAMILLE_NORM '= BEFORE."
"A"." NOM_FAMILLE_NORM')
filter ("A". "C_INDIVIDU"

Edit-

Just to add that Oracle will use your index because you don't have any starting by conditions so the entire table must be completely digitized. Once the table has been fully scanned it will be in pga is probably still easier to read PGA rather than analysis of the index to find the following lines in the connection by.

Tags: Database

Similar Questions

  • Query design problem (possibly use of hierarchical query)?

    I have tables with the following structure:
    WITH rights AS
    (
         SELECT 1 AS OBJECT_ID FROM DUAL UNION ALL
         SELECT 2 AS OBJECT_ID FROM DUAL UNION ALL
         SELECT 3 AS OBJECT_ID FROM DUAL UNION ALL
         SELECT 4 AS OBJECT_ID FROM DUAL UNION ALL
         SELECT 8 AS OBJECT_ID FROM DUAL UNION ALL
         SELECT 5 AS OBJECT_ID FROM DUAL
    ),
    OBJECTS AS
    (
         SELECT 1 AS OBJECT_ID, NULL AS PARENT_ID, 'Y' AS INHERIT, 'A' AS NAME FROM DUAL UNION ALL
         SELECT 2 AS OBJECT_ID, 1 AS PARENT_ID, 'Y' AS INHERIT, 'AB' AS NAME FROM DUAL UNION ALL
         SELECT 3 AS OBJECT_ID, 1 AS PARENT_ID, 'Y' AS INHERIT, 'AC' AS NAME FROM DUAL UNION ALL
         SELECT 4 AS OBJECT_ID, 1 AS PARENT_ID, 'Y' AS INHERIT, 'AD' AS NAME FROM DUAL UNION ALL
         SELECT 5 AS OBJECT_ID, 2 AS PARENT_ID, 'Y' AS INHERIT, 'ABE' AS NAME FROM DUAL UNION ALL
         SELECT 6 AS OBJECT_ID, 5 AS PARENT_ID, 'Y' AS INHERIT, 'ABEF' AS NAME FROM DUAL UNION ALL
         SELECT 7 AS OBJECT_ID, 5 AS PARENT_ID, 'N' AS INHERIT, 'ABEG' AS NAME FROM DUAL UNION ALL
         SELECT 8 AS OBJECT_ID, 7 AS PARENT_ID, 'Y' AS INHERIT, 'ABEGH' AS NAME FROM DUAL UNION ALL
         SELECT 9 AS OBJECT_ID, 8 AS PARENT_ID, 'N' AS INHERIT, 'ABEGHI' AS NAME FROM DUAL
    )
    I want to return All THE CHILDREN for a PARENT GIVES according to the following conditions:

    1 return the children IF OBJECT_ID of the child exist rights
    2 return the children if the child is INHERIT = 'Y' AND it travels upward the tree until one of the ancestors are rights until INHERIT it has not changed of 'Y' "n" and return to 'Y' as one traverses the tree.

    I am running Oracle 10.2.0.4.

    I started to set up a SQL statement and it looks like the following:
    SELECT OBJECTS.*
    FROM     OBJECTS
    ,     RIGHTS
    WHERE     OBJECTS.OBJECT_ID = RIGHTS.OBJECT_ID
    AND   OBJECTS.PARENT_ID = <PARENT ID>
    OR     (OBJECTS.INHERIT='Y' AND OBJECTS.PARENT_ID = RIGHTS.OBJECT_ID)
    However, this does not address the requirement because they believe that if the parent record exists in the RIGHTS table. The parent record might INHERIT = 'Y '.

    That's why I need to be able to cross the child to the top of the tree, stopping only at the following conditions:

    1 always INHERIT = 'Y' and the 'root' OBJECT_ID is in the RIGHTS table.
    2. up to INHERIT = ' only and the OBJECT_ID is in the RIGHTS table.

    With this in mind, I am considering a query with the following structure:
    SELECT OBJECTS.*
    FROM     OBJECTS
    ,     RIGHTS
    WHERE     OBJECTS.OBJECT_ID = RIGHTS.OBJECT_ID
    AND   OBJECTS.PARENT_ID = <PARENT ID>
    OR     (
              OBJECTS.INHERIT='Y' 
              AND 
              EXISTS(return 1 if one of the parents exists in the RIGHTS table) 
         )
    Let me know if you have any questions.

    I added some additional data. I expect the following results:
     OBJECT_ID  PARENT_ID I NAME
    ---------- ---------- - ------
             1            Y A
             2          1 Y AB
             3          1 Y AC
             4          1 Y AD
             5          2 Y ABE
             6          5 Y ABEF
             8          7 Y ABEGH
    Thank you!

    Published by: Centinul on April 7, 2009 07:09

    Added additional information...

    Hello

    Thanks for posting the sample data in a convenient form. This helps a lot.

    I think that's what you want. (You don't post the results, I can't be sure.)

    SELECT     *       -- or whatever
    FROM          objects     o
    LEFT OUTER JOIN     rights     r     ON     o.object_id     = r.object_id
    START WITH     o.parent_id     IS NULL
            AND     r.object_id     IS NOT NULL
    CONNECT BY     o.parent_id     = PRIOR o.object_id
         AND     (          o.inherit     = 'Y'
              OR          r.object_id     IS NOT NULL
              )
    ;
    

    This includes all of your data sample except for the line where object_id = 7.
    If this line were descendants, they would not be included, even if they inherit = "Y" or a correspondence in the rights table. I hope that's what you want. There is no example of this in the sample data, so I'm not sure.

  • [Oracle 8i] Need help of a hierarchical query pruning branches

    My problem is that my hierarchical query seems only to cut values that do not meet my criteria, but still includes their children. When my query hits a record that does not meet my criteria, I want it to stop there. I tried including the criteria in just the ' ' a where clause of the query and also put the criteria in clause "connect by" as well, but nothing has been set. Will you please keep in mind that I'm using Oracle 8i, so I can't use some of the "nice" statements for hierarchical queries that they introduced in 9. I'm stuck with "Start With... Connect in "."

    I have examples of tables/data I can post if someone needs to see to help me, but to start with, here my current query:
    SELECT     *
    FROM     (
              SELECT 
                   LEVEL
              ,     c_bill.comp_part_nbr                     AS     c_part_nbr
              ,     (select c_part.part_desc 
                   FROM part c_part 
                   WHERE c_part.part_nbr=c_bill.comp_part_nbr)     AS     c_part_desc
              ,     (SELECT c_part.part_type 
                   FROM part c_part 
                   WHERE c_part.part_nbr=c_bill.comp_part_nbr)      AS     c_part_type
              ,     c_bill.qty_per                          AS     c_qty_per_p
              ,     c_bill.qty_per_type                     AS     c_qty_per_type
              ,     (SELECT c_part.qty_on_hand                
                   FROM part c_part 
                   WHERE c_part.part_nbr=c_bill.comp_part_nbr)      AS     c_qty_on_hand
              ,     c_bill.oper_nbr                     AS     rqd_at_op
              ,     c_bill.comp_off_adj                     AS     rqd_offset
              ,     c_bill.bom_doc_nbr                     AS     p_part_nbr
              ,     (SELECT p_part.qty_on_hand 
                   FROM part p_part 
                   WHERE p_part.part_nbr=c_bill.bom_doc_nbr)      AS     p_qty_on_hand
              FROM 
                   BILL c_bill 
              WHERE 
                   (
                             (c_bill.status           =      'RL')           
                        AND     (c_bill.view_code     IN      ('M','G'))     
                        AND     (c_bill.end_eff_dt     >      SYSDATE)       
                        AND     (c_bill.begn_eff_dt     <=      SYSDATE)
                   ) 
              START WITH c_bill.bom_doc_nbr=RPAD(?,25)
              CONNECT BY PRIOR c_bill.comp_part_nbr=c_bill.bom_doc_nbr
              AND     c_bill.view_code     IN     ('M','G')     
              AND     c_bill.status          =     'RL'
              AND      c_bill.end_eff_dt     >     SYSDATE
              AND     c_bill.begn_eff_dt     <=     SYSDATE     
         ) a
    WHERE     c_part_type = 'M'

    Hello

    The criterion in the outer query

    c_part_type = 'M'
    

    applies only to the results; You can still get the descendants of these lines in the output. This seems to be the only thing that is not repeated in the CONNECT BY clause.

    If you don't want to repeat the criteria in the WHERE clause and the CONECT BY clause, you can apply them once in a view online.
    The following example works in Oracle 8.1:

    SELECT     LPAD ( ' '
              , 3 * (LEVEL - 1)
              ) || ename          AS iname
    ,     empno
    ,     mgr
    FROM     (     -- Begin in-line view of employees named C-Z
         SELECT     ename
         ,     empno
         ,     mgr
         FROM     scott.emp
         WHERE     ename     >= 'C'
         )     -- End in-line view of employees named C-Z
    START WITH     mgr    IS NULL
    CONNECT BY     mgr    = PRIOR     empno
    ;
    

    Not only is excluded BLAKE, but the descendants of JAMES BLAKE, MARTIN, etc. are excluded, too, without repeating the condition.

    Please, post CREATE TABLE and INSERT statements for some examples of data - just enough to show what is the problem - and the results desired from these data.

  • Problems with views based on a hierarchical query

    Datamodeler 3.1.3.706 (SQL Dev 3.2.10.09):

    When you create a view that uses a hierarchical query, the query designer encounter various difficulties:

    When pasting in the SQL code, if the notice is registered without first clicking the schema update button, the object in the entity-relationship diagram view provides a faithful representation of the view without errors, but when the reopening of the view, the code is missing.

    Simple example with the classic emp table:
    SELECT level lev
          , emp.*
       FROM emp
      CONNECT BY prior empno = mgr
      START WITH mgr        IS NULL
    If you press the schema update button to refresh the display. He mangles connect it by the clause and the view gets marked with a warning/error icon in the diagram of the relationships, but the now decomposed code remains available on reopening of the query designer.

    Same code as above after having clicked on the button of update of schema:
     SELECT Level lev
    , emp.*
       FROM emp
      CONNECT BY
    Other issues are met if the query contains a column CONNECT_BY_ % nickname hierarchical:
    SELECT level
          , emp.*
          , connect_by_root emp.ename root_ename
       FROM emp
      CONNECT BY prior empno = mgr
      START WITH mgr        IS NULL;
    In this case, paste in the code and clicking Update schema button or the OK button translates into a "unexpected Token' error analysis.

    These problems are encountered with the logic model and the relational.

    Is this a known issue? I searched this forum but have not found any references to this.

    Thank you

    Sentinel

    Hi, Sentinel,

    I logged a bug for this.
    You can try 3.3 DM treat it better first problem, analysis of connect_by_root operator will pass if you do not alias.

    Philippe

  • Hierarchical query help

    Version: Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production

    Hello

    I can't just writing this hierarchical query.

    CREATE TABLE resources
    (
        resource_name   VARCHAR2( 20 )
       ,resource_id     NUMBER
       ,resource_mgr_id NUMBER
    );
    
    INSERT INTO resources(resource_name,resource_id,resource_mgr_id)
    VALUES ('Phupinder',29269,29298);
    
    INSERT INTO resources(resource_name,resource_id,resource_mgr_id)
    VALUES ('Terry',29298,NULL);
    
    INSERT INTO resources(resource_name,resource_id,resource_mgr_id)
    VALUES ('Matt',4876,32942);
    
    INSERT INTO resources(resource_name,resource_id,resource_mgr_id)
    VALUES ('Bryan',29429,29269);
    
    INSERT INTO resources(resource_name,resource_id,resource_mgr_id)
    VALUES ('Cathy',32942,4922);
    
    INSERT INTO resources(resource_name,resource_id,resource_mgr_id)
    VALUES ('Scott',4257,29429);
    
    INSERT INTO resources(resource_name,resource_id,resource_mgr_id)
    VALUES ('Joe',44026,4876);
    
    INSERT INTO resources(resource_name,resource_id,resource_mgr_id)
    VALUES ('Greg',4922,4257);
    
    
    
    
    
    
    
    
    

    I also tried this:

    1. SELECT DISTINCT R.resource_name
    2. r.resource_id
    3. From r resources
    4. WHERE r.resource_id IN (SELECT DISTINCT r2.resource_mgr_id
    5. RESOURCE r2
    6. WHERE r.resource_id = r2.resource_mgr_id OR
    7. R2.resource_mgr_id IS NULL)
    8. ORDER BY 1;

    Which gives correct results, but isn't that a hierarchical query?

    It was the (almost) good solution to your problem.

    The only thing is:

    -you don't need to do a correlated subquery to solve the problem

    -you don't need to separate your subqurey

    -you don't need to separate your mainquery

    SELECT resource_name, id_ressource

    RESOURCES

    where id_ressource in (select r2.resource_mgr_id from r2 resources);

    would be sufficient.

    HTH

  • Problem strange Contact ringtone after update

    No matter how I set my settings when I get a call from a person (someone) in my contact list , I get a strange ring that is not yet listed as a ringer option. It's the kind of boop boop boop ringtone that is too quiet and it's really annoying. If someone calls, which isn't in my contact list, it sounds with the normal ring, that I have set myself .

    I tried:

    Change the ringtone under setting > Sound > ringtone

    Change the ringtone for a contact under Edit > add Info > ringtone and if it is set to 'No specified ring' or I actually choose a ringtone is still the boop boop boop ringtone.

    I cleaned the database of all the contacts folder and restored from Gmail.

    I have not installed custom ringtones.

    I googled this problem and saw that a few other people have had this problem with the ringtone problem strange boop boop boop but the only solution they offered was a hard reset, which I prefer not to do. A hard reset is similar to reload your operating system on your computer just to solve a little problem. I've been in it for 30 years and rarely use a reformatting/reload.

    There must be a more elegant solution to this problem for all reset. It would take me a week to get everything back to the top of the way I like it!

    Anyone?

    Thank you!

    Mike

    Thanks Joel!

    Forgot Droid had a safe mode! Boot in SafeMode returned the correct tone. Using titanium backup, I froze the user applications installed one time until I found the culprit. It turned out to be Norton. Deleted the data for this app, restarted and now everything is back to normal!

    The option of 'Freeze' Titanium is great! Beats the heck out of uninstalling, then reinstalling applications.

    Thanks again!

    Mike

  • Query on hierarchical query in interactive report!

    Hello

    In Apex Oracle 5.1, I tried to use an interactive report to view details of employee based on a hierarchy. I used the query to display data below:

    SELECT last_name, employe_id, manager_id, LEVEL

    Employees

    START WITH employee_id = 100

    CONNECT BY PRIOR employee_id = manager_id

    Brothers and SŒURS of ORDER BY last_name;

    The output was as below:

    LAST_NAME EMPLOYEE_ID MANAGER_ID LEVEL

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

    King                                100                                                       1

    Cambrault                        148                                 100                 2

    Bates                              172                                 148                 3

    Bloom                             169                                  148                3

    Fox                                 170                                  148                3

    Kumar                             173                                  148                3

    Ozer                                168                                  148               3

    Smith                               171                                  148              3

    De Haan                           102                                   100             2

    Hunold                              103                                   102             3

    Austin                               105                                   103             4

    Ernst                                 104                                   103             4

    Lorentz                              107                                   103             4

    Pataballa                           106                                    103            4

    Errazuriz                           147                                   100              2

    Ande                                 166                                    147             3

    Banda                               167                                     147             3

    ...

    Now, I would like to display data based on the connection of employees.

    For example (based on above request): If an employee named - Cambrault is the login, only employees under him (Bates, Bloom, Fox, Kumar, Smith, Ozer) and its own contact information should appear in the report.

    Please advise.

    Kind regards

    mebu

    Mebu wrote:

    I used a hierarchical query. But based on Login, I want to display only members under him.

    For example: If Cambrault LOGIN, only employees under him (Bates, Bloom, Fox, Kumar, Smith, Ozer) and its own coordinates must display in Oracle Apex.

    SELECT last_name, employe_id, manager_id, LEVEL

    Employees

    START WITH employee_id = 100

    CONNECT BY PRIOR employee_id = manager_id

    Brothers and SŒURS of ORDER BY last_name;

    See what/when/where? How to get the answers from the forum

    Describe the requirements clearly and completely, using the APEX, Oracle and terminology of web standard.

  • hierarchical query of VO in the ofa page

    Hello

    I try to use the hierarchical query in VO for the display of all levels of supervisors for employee and want to display in populist:

    This is the query

    REPLACE SELECT distinct (mgx.full_name, "',' ') supervisor_full_name;

    XPP. Employee_number

    OF per_assignments_x pax,.

    per_people_x ppx,

    per_people_x mgx,

    per_positions pp,

    per_jobs pj,

    per_position_definitions ppd

    WHERE ppx.person_id = pax.person_id

    AND ppx.current_employee_flag = 'Y '.

    AND mgx.person_id = pax.supervisor_id

    AND pp.position_id = pax.position_id

    AND pj.job_id = pax.job_id

    AND ppd.position_definition_id = pp.position_definition_id

    START WITH ppx.employee_number =: 1

    CONNECT BY PRIOR MGX.employee_number = ppx.employee_number AND LEVEL < 6

    I'm trying to get this VO implemented PR when I run the page in jdeveloper with parameter binding, it's getting error.

    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: 27122 Houston: SQL error in the preparation of the statement.

    I would like to delete the parameter binding and executing CO VO past these two statements may be:

    START WITH ppx.employee_number =: 1

    CONNECT BY PRIOR MGX.employee_number = ppx.employee_number AND LEVEL < 6

    How can I do?

    Thank you

    MK

    has worked?

  • Help with hierarchical query

    I'm trying to parse each string inside of individual characters. For this, I used the link by the hierarchical query clause. I am not able to use connect by correctly. Here is my example.

    with the CBC as)

    Select 1: the nurse, 'abc' double union all Str

    Select 2: the nurse, '123' Str of all union double

    Select 3: the nurse, "pqr xyz" dual union all Str

    Select option 4: the nurse, 'john doe' double Str

    )

    Select the level, homobasidiomycetes, substr(s.str,level,1) as chr

    s of the CBC

    connect nocycle level < = length (homobasidiomycetes)

    /

    The above query returns 3 028 lines when I want that 21. Adding a distinct to select, it's what I want.

    with the CBC as)

    Select 1: the nurse, 'abc' double union all Str

    Select 2: the nurse, '123' Str of all union double

    Select 3: the nurse, "pqr xyz" dual union all Str

    Select option 4: the nurse, 'john doe' double Str

    )

    Select distinct level, homobasidiomycetes, substr(s.str,level,1) as chr

    s of the CBC

    connect nocycle level < = length (homobasidiomycetes)

    order by str, level

    /

    For a large data set I could end up with several million rows before the separate would lead. So, how can I restrict the connection by clause to go within each line.

    Assuming that the AI is the primary key, you could do this:

    with src as (
      select 1 as rn, 'abc' as str from dual union all
      select 2 as rn, '123' as str from dual union all
      select 3 as rn, 'pqr xyz' as str from dual union all
      select 4 as rn, 'john doe' as str from dual
    )
    select level,
          s.str,
          substr(s.str,level,1) as chr
    from src s
    connect by level <= length(s.str)
              and prior rn = rn
              and prior dbms_random.value is not null;
    

    See DBMS_RANDOM.value in a hierarchical solution for string to table? for an exchange of views around the case.

  • Hierarchical query result

    Dear all

    I use Oracle Database 10g and I need a hierarchical query giving following release

    KING

    | __JONES

    |   | __SCOTT

    |   | __ADAMS

    |   | __FORD

    |      | __SMITH

    | __BLAKE

    |   | __ALLEN

    |   | __WARD

    |   | __MARTIN

    |   | __TURNER

    |   | __JAMES

    | __CLARK

    | __MILLER

    Best regards

    Try this

    SELECT CASE WHEN level > 1 THEN LPAD (': _ ', LEVEL,' |) ')

    END | Ename AS ename_tree

    WCP

    START WITH mgr IS NULL

    CONNECT BY PRIOR empno = mgr;

  • How to write a hierarchical query so that only the child nodes are displayed?

    Hi all

    I have a hierarchical query that I use in an area of tree demand APEX and there are nodes that have no children and I am trying to find a way to not display these nodes. Essentially if the user does not have to develop a lot of knots to know that nothing exists at the most detailed level.

    The data are based on the Oracle Fusion FND tables but for example purposes here is enough data to illustrate my question:


    create table APPL_TAXONOMY_HIERARCHY (SOURCE_MODULE_ID varchar2(30), TARGET_MODULE_ID varchar2(30));
    create table APPL_TAXONOMY_TL (module_id varchar2(30), description varchar2(100), user_module_name varchar2(30), language varchar2(5));
    create table APPL_TAXONOMY (MODULE_ID    varchar2(30),    MODULE_NAME    varchar2(30), MODULE_TYPE varchar2(10),    MODULE_KEY varchar2(30));
    create table TABLES (table_name varchar2(30), module_key varchar2(30));
    
    

    insert into APPL_TAXONOMY_TL values ('1', null, 'Oracle Fusion', 'US' );
    insert into APPL_TAXONOMY_TL values ('2', null, 'Financials', 'US' );
    insert into APPL_TAXONOMY_TL values ('3', null, 'Human Resources', 'US' );
    insert into APPL_TAXONOMY_TL values ('20', null, 'Accounts Payable', 'US' );
    insert into APPL_TAXONOMY_TL values ('10', null, 'General Ledger', 'US' );
    
    insert into APPL_TAXONOMY_HIERARCHY values ('1', 'DDDDDDDD');
    insert into APPL_TAXONOMY_HIERARCHY values ('2', '1');
    insert into APPL_TAXONOMY_HIERARCHY values ('3', '1');
    insert into APPL_TAXONOMY_HIERARCHY values ('4', '1');
    insert into APPL_TAXONOMY_HIERARCHY values ('10', '2');
    insert into APPL_TAXONOMY_HIERARCHY values ('20', '2');
    
    insert into APPL_TAXONOMY values ('1', 'Fusion', 'PROD', 'Fusion');
    insert into APPL_TAXONOMY values ('2', 'Financials', 'FAMILY', 'FIN');
    insert into APPL_TAXONOMY values ('10', 'GL', 'APP', 'GL');
    insert into APPL_TAXONOMY values ('3', 'Human Resources', 'FAMILY', 'HR');
    insert into APPL_TAXONOMY values ('20', 'AP', 'APP', 'AP');
    
    insert into tables values ('GL_JE_SOURCES_TL','GL');
    insert into tables values ('GL_JE_CATEGORIES','GL');
    

    My hierarchical query is as follows:

    with MODULES as
    (
    SELECT h.source_module_id, b.user_module_name, h.target_module_id
          FROM APPL_TAXONOMY_HIERARCHY H,
          APPL_TAXONOMY_TL B,
    APPL_TAXONOMY VL
    where H.source_module_id = b.module_id
    and b.module_id = vl.module_id
    and vl.module_type not in ('PAGE', 'LBA')
    UNION ALL
    select distinct table_name, table_name,  regexp_substr(table_name,'[^_]+',1,1) 
    from TABLES --needed as a link between TABLES and APPL_TAXONOMY
    union all
    select module_key as source_module_id, module_name as user_module_name, module_id as target_module_id  from appl_taxonomy VL where VL.module_type = 'APP')
    SELECT  case when connect_by_isleaf = 1 then 0
                when level = 1             then 1
                else                           -1
           end as status,
    LEVEL,
    user_module_name as title,
    null as icon,
    ltrim(user_module_name, ' ') as value,
    null as tooltip,
    null as link
          FROM MODULES
          START WITH source_module_id = '1'
          CONNECT BY PRIOR source_module_id = target_module_id
    ORDER SIBLINGS BY user_module_name;
    

    In Oracle APEX, this gives a tree with the appropriate data, you can see here:

    https://Apex.Oracle.com/pls/Apex/f?p=32581:29 (username: guest, pw: app_1000);

    The SQL of the query results are:

    STATUSTITLE LEVELVALUE

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

    11 oracle FusionOracle Fusion
    -12 financial tablesFinancials
    -13 accounts payableAccounts payable
    04 APAP
    -1General Accounting 3General Accounting
    -14 GLGL
    05 GL_JE_CATEGORIESGL_JE_CATEGORIES
    05 GL_JE_SOURCES_TLGL_JE_SOURCES_TL
    02 human resourcesHuman resources

    The lowest level is the name of the table to level 5. HR is not any level under level 2, in the same way, "AP" (level 4) has nothing below, i.e. no level 5 and that's why I don't want to show these nodes. Is this possible with the above query?

    Thanks in advance for your suggestions!

    John

    Hello

    The following query will include only the nodes of level = 5 and their ancestors (or descendants):

    WITH modules LIKE

    (

    SELECT h.source_module_id

    b.user_module_name AS the title

    h.target_module_id

    To appl_taxonomy_hierarchy:

    appl_taxonomy_tl b

    appl_taxonomy vl

    WHERE h.source_module_id = b.module_id

    AND b.module_id = vl.module_id

    AND vl.module_type NOT IN ('PAGE', "LBA")

    UNION ALL

    SELECT DISTINCT

    table-name

    table_name

    , REGEXP_SUBSTR (table_name, ' [^ _] +')

    From the tables - required as a link between the TABLES and APPL_TAXONOMY

    UNION ALL

    SELECT module_key AS source_module_id

    AS user_module_name module_name

    module_id AS target_module_id

    Of appl_taxonomy vl

    WHERE vl.module_type = 'APP '.

    )

    connect_by_results AS

    (

    SELECT THE CHECK BOX

    WHEN CONNECT_BY_ISLEAF = 1 THEN 0

    WHEN LEVEL = 1 THEN 1

    OF ANOTHER-1

    The END as status

    LEVEL AS lvl

    title

    -, NULL AS icon

    , LTRIM (title, "") AS the value

    -, NULL as ToolTip

    -, Link AS NULL

    source_module_id

    SYS_CONNECT_BY_PATH (source_module_id - or something unique

    , ' ~' - or anything else that may occur in the unique key

    ) || ' ~' AS the path

    ROWNUM AS sort_key

    Modules

    START WITH source_module_id = '1'

    CONNECT BY PRIOR Source_module_id = target_module_id

    Brothers and SŒURS of ORDER BY title

    )

    SELECT the status, lvl, title, value

    -, icon, tooltip, link

    OF connect_by_results m

    WHEN THERE IS)

    SELECT 1

    OF connect_by_results

    WHERE the lvl = 5

    AND the path AS ' % ~' | m.source_module_id

    || '~%'

    )

    ORDER BY sort_key

    ;

    You may notice that subqueries modules and the connect_by_results are essentially what you've posted originally.  What was the main request is now called connect_by_results, and it has a couple of additional columns that are necessary in the new main request or the EXISTS subquery.

    However, I am suspicious of the 'magic number' 5.  Could you have a situation where the sheets you are interested in can be a different levels (for example, some level = 5 and then some, into another branch of the tree, at the LEVEL = 6, or 7 or 4)?  If so, post an example.  You have need of a Query of Yo-Yo, where you do a bottom-up CONNECT BY query to get the universe of interest, and then make a descendant CONNECT BY query on this set of results.

  • Support for hierarchical query

    Hi all

    I must be tired and can't think clearly, so I am a little confused the following query.

    The environment is Oracle 9i:

    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64 bit Production

    PL/SQL Release 9.2.0.8.0 - Production

    CORE Production 9.2.0.8.0

    AMT for HP - UX: 9.2.0.8.0 - Production Version

    NLSRTL Version 9.2.0.8.0 - Production

    Suppose I have the following data:

    with mydata as

    (

    Select the code 1, code_high, null, 'John' cname 'Smith' csurname, 'X' union resp. double all the

    Select 2 code, 1 code_high, cname 'Bill', 'White' csurname, RESP null in union double all the

    Select 3 code, code_high 2, 'Fred' cname 'Reed' csurname, 'X' union resp. double all the

    Select 4 code, code_high, null, 'Tim' cname 'Hackman' csurname, 'X' union resp. double all the

    Select code 5, code_high 4, 'John', 'Reed' cname csurname resp null in union double all the

    Select 6 code, code_high 5, cname 'Bill', 'Hakcman' csurname, 'X' union resp. double all the

    Select the code 7, code_high 6, cname 'Fred' csurname 'White', null union resp. double all the

    Select code 8, code_high 7, 'Bill' cname 'Smith' csurname, resp. union null double all the

    Select 9 code, code_high 8, cname "Tom", "Reed" csurname, null double RESP

    )

    Select *.

    of mydata;

    CODE CODE_HIGH CNAME CSURNAME RESP

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

    John Smith 1 X

    2 1 bill White

    3 2 Fred Reed X

    4 Tim Hackman X

    5 4 John Reed

    6 5 bill Hakcman X

    7 6 Fred white

    8 7 bill Smith

    9 8 Tom Reed

    It is a hierarchical query where code_high represents the father.

    I need to find in the hierarchy of higher level responsible for each code.

    Suppose I want to find in the hierarchy, one with resp = 'X '.

    Run the following query I find for the code = 9

    Select phone, cname, csurname code

    of mydata

    When resp = 'X '.

    and rownum = 1

    Connect prior code_high = code

    start with code = 9;

    CODE CNAME CSURNAME

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

    Bill 6 Hakcman

    Is there a way to get the full list with the loaded correspondents.

    The expected results are:

    CODE CODE_HIGH CNAME CSURNAME RESP. RESP_CODE RESP_NAME RESP_SURNAME

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

    1 John Smith John Smith 1 X

    2 1 bill White 1 John Smith

    3 2 Fred Reed X 3 Fred Reed

    Tim Hackman 4 X 4 Tim Hackman

    5 4 John Smith 4 Tim Hackman

    6 5 bill Hakcman Bill Hakcman 6 X

    7 6 Fred White 6 Bill Hakcman

    8 7 bill Smith 6 Bill Hakcman

    9 8 Tom Reed 6 Bill Hakcman

    Kind regards.

    Alberto

    Hi, Alberto.

    I know that you are using Oracle 9; That's why I mentioned that you would have to use a substitute for CONNECT_BY_ROOT.  Before I could show how, I saw the solution of the Padders, which is probably simpler and more efficient for this work.  Padders used REGEXP_SUBSTR, which is not available in Oracle 9, but you can use SUBSTR and INSTR instead.

    Here is the solution of the Padders for Orcle 9:

    WITH got_resp_path AS

    (

    SELECT m.*

    RTRIM (SYS_CONNECT_BY_PATH (CASE

    WHEN resp = 'X '.

    THEN the code

    END

    , ' '

    )

    ) AS resp_path

    OF mydata m

    START WITH code_high IS NULL

    CONNECT BY code_high = code PRIOR

    )

    C. SELECT

    r.code AS resp_code

    r.cname AS resp_name

    r.csurname AS resp_surname

    OF got_resp_path c

    JOIN mydata r ON r.code = TO_NUMBER (SUBSTR (c.resp_path

    INSTR (c.resp_path

    , ' '

    -1

    )

    )

    )

    ORDER BY c.code

    ;

    I agree that what you posted in your last post is not very satisfactory.  Rather than make a CONNECT a separate query for each column of resp_ you want to view, you can modify it to get only the unique code and then use it in a join, as Padders, to get all the other columns you need.

  • In a hierarchical query, is it possible for a line having more than one immediate ancestor?

    Hello

    Question:

    In a hierarchical query, is it possible for a line having more than one immediate ancestor?


    Answer:



    Isn't it?  Surely this is Yes?


    Thank you

    Jason

    Line may have ancestors as much as you want. It goes the same for successors.

    SY.

  • Hierarchical data, how to aggregate over levels in hierarchical query?

    Hello

    I hope someone can help me.

    I held in a data table ("" what part was built in what other part of when when? "')
    ID parent_id build_in build_out
    1 NULL NULL NULL
    2/1 2010 2012
    3 2 2011 2013
    4 2 2013 NULL

    What are the parts is stored in a separate table.

    Now I want to know when when which part was built in the first level, in the example, I want to know that
    1 was simply a part of 1
    2 was part of 1 between 2010 and 2012
    3 was part of 1 between 2011 and 2012
    4 has never been a part of 1

    I tried several approaches - if there is a fixed number of levels between the types, I am interested I can do using joins and more/less (similarly as some nvl). Unfortunately this is not always the case (some parts appear on several levels).
    If I'm only interested in the parts that are never deleted, I can get by using a style of connect request and get the current configuration. But I can't seem to understand the time connecting part to the high level in such a query, or even filtering absurd combinations (like "4 in 1" in the example above). I could deal with the data recovered outside the database, but I prefer not.

    Is there a way to obtain the hierarchical data with an aggregate (min, max) for all levels?

    What version of Oracle you are on?

    In 11.2.x, you can use the recursive subquery factoring. Something like

    with t (id, parent_id, build_in, build_out) as (
    select 1, null, null, null from dual union all
    select 2, 1, 2010, 2012 from dual union all
    select 3, 2, 2011, 2013 from dual union all
    select 4, 2, 2013, null from dual
    )
    , c1 (root_id, id, parent_id, build_in, build_out) as (
    select id, id, parent_id, 0, 9999
    from t
    where parent_id is null
    union all
    select root_id, t.id, t.parent_id
    , greatest(nvl(t.build_in,0), nvl(b.build_in,0))
    , least(nvl(t.build_out,9999), nvl(b.build_out,9999))
    from c1 b, t
    where b.id = t.parent_id
    )
    select * from c1
    where build_in < build_out
    ;
    ROOT_ID ID    PARENT_ID  BUILD_IN  BUILD_OUT
    ------- ----- ---------- --------- ----------
    1       1                0         9999
    1       2     1          2010      2012
    1       3     2          2011      2012      
    

    With a hierarchical query by using the syntax connection, you could do something like

    select * from (
    select connect_by_root id as root, id
    , greatest(nvl(build_in,0), nvl(prior build_in,0)) as max_in, least(nvl(build_out,9999), nvl(prior build_out,9999)) as min_out
    from t
    start with parent_id is null
    connect by parent_id = prior id
    )
    where max_in < min_out
    ;
    

    but it is not powerful enough. This version compares the dates between a current and previous levels, but the recursive subquery is to compare the dates in the current level for the winners of the comparisons to the previous level. Not sure if it's an important distinction for your needs, however.

    If you are on 11.2 I advise to use the recursive subquery factoring. If this isn't the case, you can try the link by version.

    Kind regards
    Bob

  • Getting the line without the use of hierarchical query values

    Hi all


    I want to know the hierarchical values without using a hierarchical query. I have two tables EMP, DEPT

    EMP table is to have two columns (empid, mgrid)
    DEPT table is to have two columns (deptid, empid)

    Data of the EMP

    1,
    2, 1
    3, 2
    4, 3

    Data DEPT

    10, 1

    Each time, I gave deptid = 10, I need to know the this deptid empid then who is this empid (child levels as well). In this case, the output should be
    1
    2
    3
    4

    I don't want to use hierarchical query.

    Thanks in advance.


    Thank you
    PAL

    You can use the RECURSIVE subquery, if you are 11 GR 2, like this

    SQL> with EMP (empid,mgrid) as
      2  (
      3  select 1,null from dual union all
      4  select 2, 1 from dual union all
      5  select 3, 2 from dual union all
      6  select 4, 3 from dual
      7  ),
      8  dept(deptid,empid) as
      9  (
     10  select 10, 1  from dual
     11  ),
     12  t(empid,mgrid) as
     13  (
     14  select empid,mgrid
     15  from emp e
     16  where empid in (
     17      select d.empid
     18      from dept d
     19      where deptid = 10
     20                  )
     21  union all
     22  select e.empid,e.mgrid
     23  from emp e, t
     24  where e.mgrid = t.empid
     25  )
     26  select *
     27  from t;
    
         EMPID      MGRID
    ---------- ----------
             1
             2          1
             3          2
             4          3
    

    Yet, the question is valid - why can't use you a hierarchical query?

    Published by: JAC on May 29, 2013 12:37

Maybe you are looking for

  • clicked "never allow" for a program to run. need to change this.

    I recently downloaded the steam 2 Team Fortress and when I went to run the program, a window pops up with the buttons "never allow, allow once, always allow". I have been followed and accidentally clicked on never leave out. now when I try to run tea

  • Dynadock U3.0 win 8 - Ethernet and Audio does not

    Hello I recently bought a UX31A Ultrabook and the Toshiba Dynadock U3.0. My computer is running 64-bit Windows 8. I followed the installation instructions to the letter and that you have installed DisplayLink 71M 1, however I can not the ethernet or

  • FaceTime invalid unique id

    After having upgraded my iMac end 2013 at El Capitan 10.11.1, Facetime camera (built in) does not work in Facetime, iMessgae, Skype and... but it works with iMovie and FinalCut Pro. I tried a lot of help from previous discussions, but the problem sti

  • How to restore the winre_drv, system_drv and etc.

    I'm trying to clean install windows 8... so I complete wipe all the partition include system_drv and winre_drv and all of em is anyway to return? What is the risk if we delete those partition? -I don't have a backup my laptop Ideapad z500 Gimme pleas

  • Disable Windows Update

    HelloHow can I disable Windows Update?THX