Duplicates in hierarchical query results

Please use the suite of applications:

CREATE TABLE EMP

(NUMBER OF EMP_ID,

EMP_NAME VARCHAR2 (50).

NUMBER OF MANAGER_ID

);

INSERT INTO EMP VALUES(1,'SCOTT',);

INSERT INTO EMP VALUES(2,'JOHN',1);

INSERT INTO EMP VALUES(3,'ROB',2);

INSERT INTO EMP VALUES(4,'MIKE',2);

INSERT INTO EMP VALUES(5,'BOB',);

INSERT INTO EMP VALUES(6,'JEFF',5);

COMMIT;

SELECT * FROM EMP, (SELECT EMP_ID FROM EMP WHERE EMP_ID IN (1.5)) TEMP

START BY EMP. EMP_ID = TEMP. EMP_ID

CONNECT BY PRIOR EMP. EMP_ID = EMP. MANAGER_ID;

Basically, I first spend a few emp_ids a subquery and then want to see all records in the table emp which are direct or indirect of those emp_ids children.

But I get a lot of duplicate records. Can someone explain what is the reason behind this? I can use SEPARATE and spend, but there could be a problem with my request in the first place.

Help, please!

Thank you

RN

Hello

RN says:

Please use the suite of applications:

CREATE TABLE EMP

(NUMBER OF EMP_ID,

EMP_NAME VARCHAR2 (50).

NUMBER OF MANAGER_ID

);

INSERT INTO EMP VALUES(1,'SCOTT',);

INSERT INTO EMP VALUES(2,'JOHN',1);

INSERT INTO EMP VALUES(3,'ROB',2);

INSERT INTO EMP VALUES(4,'MIKE',2);

INSERT INTO EMP VALUES(5,'BOB',);

INSERT INTO EMP VALUES(6,'JEFF',5);

COMMIT;

SELECT * FROM EMP, (SELECT EMP_ID FROM EMP WHERE EMP_ID IN (1.5)) TEMP

START BY EMP. EMP_ID = TEMP. EMP_ID

CONNECT BY PRIOR EMP. EMP_ID = EMP. MANAGER_ID;

Basically, I first spend a few emp_ids a subquery and then want to see all records in the table emp which are direct or indirect of those emp_ids children.

But I get a lot of duplicate records. Can someone explain what is the reason behind this? I can use SEPARATE and spend, but there could be a problem with my request in the first place.

Help, please!

Thank you

RN

Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.

When you do CONNECT BY and joins in the same query (sub-), joins are made first, and then CONNECT BY is performed on all results of the joints.  In this example, you make a cross of PMCs and this join called temp.  Let's see what the result set looks like:

SELECT *.

WCP

,       (

SELECT emp_ID

WCP

WHERE emp_id IN (1.5)

) temp

;

Output:

EMP_ID, EMP_NAME MANAGER_ID EMP_ID

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

1 SCOTT 1

2 1 1 JOHN

3 ROB                 2          1

4 1 2 MIKE

5 BOB                            1

JEFF 6 5 1

1 SCOTT 5

2 1 5 JOHN

3 ROB                 2          5

4 2 5 MIKE

5 BOB                            5

6 5 5 JEFF

Now, you do a CONNECT BY query on the result set.  As you can see, there are 2 lines with emp_id = 2 in the set of results above, which explains why there are 2 lines in your query results with emp_id = 2.  Similarly, the output defined above, there are 2 lines with emp_id = 3, and they all have two manager_id = 2, each of them is considered to be a child of each of each of the 2 rows with emp_id = 2, and therefore, you have 2 * 2 = 4 lines with emp_id = 3 in the output CONNECT BY.

What is a cross here join?  Why must you temp?  Why not just a CONNECT BY questioning one emp, like this:

SELECT *.

WCP

START WITH emp_id IN (1, 5)

CONNECT BY PRIOR Emp_id = manager_id

;

?

Tags: Database

Similar Questions

  • 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;

  • 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

  • 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.

  • Hierarchical query help need to Oracle

    Hello
    I'm in a deep trouble.

    I want to do a hierarchical query in my TreeView table in oracle. But I want that the query retrieves information path between two nodes.

    Review the table below.

    ------------------------------------------------------
    Node ID | Name of the node. ID of the parent
    -----------------------------------------------------
    1A 0
    2 1
    3C0
    4 2
    -----------------------------------------------------

    What I want is that I'll give you 2 node id in the request. One is the source node and the other is the destination node.
    so if I put 1 node and node 4, I want to be the output

    1-> 2-> 4

    I want just a return line. Or there may be several rows but stands only the node of this path.

    1
    2
    4
    ----

    This means that I don't want to node 3 in the search result.


    More if I have the source as 4 node and the node of destination as 1 then I will also get an output of the query as below-
    4-> 2-> 1

    This means that the search for the query for the result in a way directional bi.


    If anyone can give me some information about who it's going to be great for me.

    Published by: user13276471 on December 31, 2012 03:21

    Hello

    Welcome to the forum!

    Assuming you have 2 separate nodes: Node_A and: node_b, you can find the hierarchy from one to the other like this:

    SELECT     SYS_CONNECT_BY_PATH (node_id, ',')     AS lineage
    FROM     table_x
    WHERE     node_id     IN (:node_a, :node_b)
    AND     LEVEL     > 1
    START WITH     node_id          IN (:node_a, :node_b)
    CONNECT BY     parent_id     = PRIOR node_id
    ;
    

    It will work if: the Node_A is an ancestor of the: node_b, or if: node_b is an ancestor of the: Node_A.
    If is the ancestor of the other, then it will produce 0 rows.

  • Reg: Hierarchical query (using connection by)

    Hi all
    I got the result with the hierarchical query in the form:
    * / qxxh *.
    * / qxxh/jxobcbg *.
    * / qxxh/jxobcbg/n00wcp4 *.
    * / qxxh/jxobcbg/n00wcp4 / 000263 x *.
    * / qxxh/jxobcbg/n00wcp4 / x 000263 / p0263 *.
    * / qxxh/jxxocbg *.
    * / qxxh/jxxocbg/n00voc1 *.
    * / qxxh/jxxocbg/n00voc1 / x 000589 *.
    * / qxxh/jxxocbg/n00voc1 / x 000589 / p0589 *.
    * / qxxh/jxuwxxh *.
    * / qxxh/jxuwxxh/n00xpxf *.
    * / qxxh, jxuwxxh, n00xpxf, m00bxpl *.
    * / qxxh/jxuwxxh/n00xpxf/m00bxpl / 000522 x *.
    * / qxxh/jxuwxxh/n00xpxf/m00bxpl / 000522 x / p0522 *.

    Here, I want to select only the maximum path. Here I used "SYS_CONNECT_BY_PATH.
    Please let meknow how to do this?
    Thanks in advance.

    Published by: udeffcv on December 9, 2009 22:03

    udeffcv wrote:
    Hi all
    I got the result with the hierarchical query in the form:
    * / qxxh *.
    * / qxxh/jxobcbg *.
    * / qxxh/jxobcbg/n00wcp4 *.
    * / qxxh/jxobcbg/n00wcp4 / 000263 x *.
    * / qxxh/jxobcbg/n00wcp4 / x 000263 / p0263 *.
    * / qxxh/jxxocbg *.
    * / qxxh/jxxocbg/n00voc1 *.
    * / qxxh/jxxocbg/n00voc1 / x 000589 *.
    * / qxxh/jxxocbg/n00voc1 / x 000589 / p0589 *.
    * / qxxh/jxuwxxh *.
    * / qxxh/jxuwxxh/n00xpxf *.
    * / qxxh, jxuwxxh, n00xpxf, m00bxpl *.
    * / qxxh/jxuwxxh/n00xpxf/m00bxpl / 000522 x *.
    * / qxxh/jxuwxxh/n00xpxf/m00bxpl / 000522 x / p0522 *.

    Here, I want to select only the maximum path. Here I used "SYS_CONNECT_BY_PATH.
    Please let meknow how to do this?
    Thanks in advance.

    Published by: udeffcv on December 9, 2009 22:03

    What do you mean by maximum path? is this...
    * / qxxh/jxobcbg/n00wcp4 / x 000263 / p0263 *.
    * / qxxh/jxxocbg/n00voc1 / x 000589 / p0589 *.
    * / qxxh/jxuwxxh/n00xpxf/m00bxpl / 000522 x / p0522 *.

    is it child nodes?
    so, you would like to see
    Column nickname... CONNECT_BY_ISLEAF example, you can find it in the link below
    http://download.Oracle.com/docs/CD/B14117_01/server.101/b10759/pseudocolumns001.htm#sthref670

    Ravi Kumar

  • [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.

  • Need help to build the query/pl-sql block to get the query result and the name of column from DB table in the form of key-value pairs.

    Hi Experts,

    I have a DB table has columns of more than 50.

    I question this table, it should only return one line at any time. as sqldeveloper below image.

    here, I need to build block pl/sql-query, Discover the column in the table as a key and query result as values.

    Eg:     Key                         -  Value

    TASK_EVENT_ID - 1765

    EVENT_TYPE - ASR_UPDATE

    ... etc until all of the columns in my table.

    Experts please comment on that point, appreciate your help on this.

    Thank you

    -Vincent.

    Here is an approach using DBMS_SQL to iterate over the columns of key / value to assign... (Little code snipped for brevity)

    create or replace procedure (task_expired)

    v_store_id in full,

    v_task_action_id in full,

    v_job_id in full

    )

    as

    -[SNIP code...]

    v_sql VARCHAR2 (4000): = ' select * from my_table where PK = 123';  -Your SQL here!

    v_v_val VARCHAR2 (4000);

    v_n_val NUMBER;

    v_d_val DATE;

    v_ret NUMBER;

    c NUMBER;

    d NUMBER;

    col_cnt INTEGER.

    f BOOLEAN;

    rec_tab DBMS_SQL. DESC_TAB;

    col_num NUMBER;

    vAsString VARCHAR2 (4000);

    BEGIN

    -[SNIP code...]

    Message_properties. CORRELATION: = "EDF_EVENT";

    MSG: = SYS. AQ$ _JMS_BYTES_MESSAGE. Construct();

    Msg.set_string_property ('queueName', ' shipping/csi_cth');

    Msg.set_string_property ('MODE', 'CR8');

    c: = DBMS_SQL. OPEN_CURSOR;

    DBMS_SQL. PARSE (c, v_sql, DBMS_SQL. NATIVE);

    d: = DBMS_SQL. Execute (c);

    DBMS_SQL. DESCRIBE_COLUMNS (c, col_cnt, rec_tab);

    1.col_cnt J

    LOOP

    CASE rec_tab (j) .col_type

    WHEN 2 THEN

    DBMS_SQL. DEFINE_COLUMN (c, j, v_n_val);      -Number

    WHEN 12 CAN

    DBMS_SQL. DEFINE_COLUMN (c, j, v_d_val);      -Date

    ON THE OTHER

    DBMS_SQL. DEFINE_COLUMN (c, j, v_v_val, 2000);   -Else treat as varchar2

    END CASE;

    END LOOP;

    LOOP

    v_ret: = DBMS_SQL. FETCH_ROWS (c);

    WHEN OUTPUT v_ret = 0;

    1.col_cnt J

    LOOP

    -Fetch each column to the correct data type based on coltype

    CASE rec_tab (j) .col_type

    WHEN 2 THEN

    DBMS_SQL. COLUMN_VALUE (c, j, v_n_val);

    vAsString: = to_char (v_n_val);

    WHEN 12 CAN

    DBMS_SQL. COLUMN_VALUE (c, j, v_d_val);

    vAsString: = to_char (v_d_val, ' DD/MM/YYYY HH24:MI:SS');

    ON THE OTHER

    DBMS_SQL. COLUMN_VALUE (c, j, v_v_val);

    vAsString: = v_v_val;

    END CASE;

    Msg.set_string_property (rec_tab (j) .col_name, vAsString);

    END LOOP;

    END LOOP;

    DBMS_SQL. CLOSE_CURSOR (c);

    DBMS_AQ. ENQUEUE (queue_name-online 'cbus.aqjms_common',

    Enqueue_options => Enqueue_options,

    Message_properties => Message_properties,

    Payload-online msg,

    Msgid => Message_handle);

    dbms_output.put_line ('00 Msgid =' |) Message_handle);

    dbms_output.put_line('===Done=');

    -[SNIP code...]

    END;

    /

  • 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?

  • Query result cache

    Today I test the query result cache, but the result is not as I expected. Please give a few advices.thank you in advance.

    SQL > create table (qrc_tab)

    Number 2);

    Table created.

    SQL > insert into qrc_tab values (1);

    1 line of creation.

    SQL > insert into qrc_tab values (2);

    1 line of creation.

    SQL > insert into qrc_tab values (3);

    1 line of creation.

    SQL > insert into qrc_tab 4;

    1 line of creation.

    SQL > insert into qrc_tab values (5);

    1 line of creation.

    SQL > create or replace function slow_function (p_id in qrc_tab.id%TYPE)

    2 back qrc_tab.id%TYPE DETERMINISTIC AS

    3 BEGIN

    4 DBMS_LOCK.sleep (1);

    5 return p_id;

    6 end;

    7.

    The function is created.

    SQL > set timing on

    SQL > select slow_function (id) in the qrc_tab;

    SLOW_FUNCTION (ID)

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

    1

    2

    3

    4

    5

    Elapsed time: 00:00:05.01

    SQL > select / * + result_cache * / slow_function (id) of qrc_tab;

    SLOW_FUNCTION (ID)

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

    1

    2

    3

    4

    5

    Elapsed time: 00:00:05.00

    SQL > select / * + result_cache * / slow_function (id) of qrc_tab;

    SLOW_FUNCTION (ID)

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

    1

    2

    3

    4

    5

    Elapsed time: 00:00:05.00

    SQL > select / * + result_cache * / slow_function (id) of qrc_tab;

    SLOW_FUNCTION (ID)

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

    1

    2

    3

    4

    5

    Elapsed time: 00:00:05.00

    I wonder why time is not fast? Help, please

    create or replace function slow_function (p_id in qrc_tab.id%TYPE)

    return qrc_tab.id%TYPE result_cache DETERMINISTIC AS

    Start

    DBMS_LOCK. Sleep (1);

    return p_id;

    end;

    /

    --

    John Watson

    Oracle Certified Master s/n

  • How to get SQL Developer 4.1 to display the query result?

    SQL DEV 4.0.3.16.84 execution of a SELECT statement is stored in a .sql file causes the window of the query result of pop-up indicating the result of a SELECT statement.  SQL DEV 4.1 is not to do so.

    Oops on my part; my SQL formatting has been the root cause.  I got used to insert split without any character of comment lines in front of them.  For example:

    ==================================================

    Select funny business;

    The foregoing indicates the behavior described.

    --==================================================

    Select funny business;

    With the dash double comment shows, the SQL works very well.

    This is different than previous versions of SQL Developer, but is probably better functionality.  I'll try to mark it as answered, but anyone with the admin should certainly do so if I can't.

  • Need help to understand the query result

    Hi gurus

    I was reading one of the question here in this forum and its link is below:

    Query required for scenario

    I had some confusion related to this code and don't understand the logic of the out put, see query below:

    Query

    with sub_services as

    (

    Select su_seq 12323, 'HLR1' so_id, 1 seq Union double all the

    Select su_seq 12323, "HLR2' so_id, seq 2 Union double all the

    Select su_seq 12323, "A09" so_id, seq 3 of all the double union

    Select su_seq 12333, "MO1" so_id, seq 4 Union double all the

    Select su_seq 12333, "MO2' so_id, seq 5 Union double all the

    Select su_seq 12333, "A09" so_id, 6 seq in union double all the

    Select su_seq 12333, 'M0CR' so_id, seq 7 Union double all the

    Select su_seq 12999, "LOL1' so_id, seq 8 Union double all the

    Select su_seq 12999, "LOL2' so_id, seq 9 double

    )

    Select *.

    of sub_services b

    where exists (select 1 from sub_services

    where su_seq = b.su_seq

    and so_id = 'A09.

    )

    order by 2;

    The query result

    12323 A09 3

    12333 6 A09

    12323 HLR1 1

    12323 HLR2 2

    12333 M0CR 7

    12333 4 MO1

    12333 5 MO2

    According to my understanding, the above query should return records in red only because of her is below command

    It exists (select 1 from sub_services

    where su_seq = b.su_seq

    and so_id = 'A09.

    but don't know why he's back 7 files, can someone help me understand the result...

    It is query is functionally identical to the PL/SQL block, but much more effective.

    declare

    number of l_res;

    Start

    for line (select *)

    sub_services) loop

    Start

    Select 1 from l_res

    of sub_services

    where su_seq = row.su_seq and

    so_id = "A09" and

    rownum = 1;

    exception when

    NO_DATA_FOUND then

    null;

    end;

    end loop;

    end;

    Essentially every row in the outer query are tested against him exists query.  Given the correlation between two requests is based only on su_seq each line with a su_seq value returned by him is returned in the output.

    Another way to think he uses instead a join condition.  This query is equivalent to the query to exist

    Select the main

    of main sub_services

    Join select (separate su_seq

    of sub_services

    where so_id = "A09") cond

    We main.su_seq = cond.su_seq;

    John

  • Need help with a query result

    Oracle Version: 11.2.0.2.0

    I need assistance with the output of the query. Here is the table.

    With Tbl_Nm as

    (

    Select 'ABC1' SYSTEM_ID, REGION 'US', 'CHI' SUB_REGION 4000 BALANCE, to_date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') LAST_UPD_TIME, 'A' FLAG of union double all the

    Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual

    )

    Select * from tbl_nm

    I need the output below.

    PQR2 UK MC 2600 1 OCTOBER 2012 04:45

    ABC1 US NY 3500 October 1, 2012 06:45

    LMN3 UK BT 2500 November 1, 2012 07:45

    The need the disc according to this system_id flagged as "A". But if the last disc of 'd' then it must show that the amount, but the file should be displayed in 'A '.

    I've tried a few and got stuck. Help, please. Not able to get a balance '.

    This question is a bit similar to needing help with a query result

    With Tbl_Nm as

    (

    Select 'ABC1' System_Id, region 'US', 'CHI' Sub_Region, 4000 balance, To_Date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') Last_Upd_Time, 'A' flag of double Union All

    Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All

    Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All

    Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual

    )

    Select System_Id, region, Sub_Region, Balance, Last_Upd_Time of Tbl_Nm T1

    where t1. Last_Upd_Time = (select max (Last_Upd_Time) in the Tbl_Nm T2 where T1.) SYSTEM_ID = T2. SYSTEM_ID)

    So maybe you'd then

    ORDER BY DECODE(flag,'D',9,1) ASC...

    to get the Ds at the end of the list.

    or

    ORDER BY CASE WHAT flag = has ' (your other filters) AND then 9 or 1 end CSA,...

    HTH

Maybe you are looking for

  • AppStore will not connect, so can't update/update

    Then, as the title suggests, my app store has not worked for a while now, and since you can only access the updates/upgrades up-to-date via the Appstore, I have a problem... Aside from that I can't update/upgrade, it is too sh * t I can't in the app

  • Portege M400: Vista does not see the CD/DVD drive

    Hello I have improved my M400 for Vista, and now it seems that I have a problem with the driver for my DVD player. I don't see a driver vista for the DVD player. Any ideas? Steve

  • DAQmx tasks name variable

    Can someone explain why use a variable LabVIEWIOControl to keep the name of the task of DAQmx, Labview causes the sequence editor to become extremely slow. The vi attached does nothing more to open a chan (output on a pxi-6723) and its closure via th

  • BIOS version 1.21 for Aspire 8930-6386

    Hi all The newest BIOS available for Aspire 8930 to the Web site of the USA is version 1.20. Apparently, there is a version 1.21 which has Intel VT enabled. I have currently VT turned on in my BIOS v 1.20 with a hack that I found on the Internet, but

  • service tag and nfc without head

    Is it possible assigned to an application when a service without head bed tag nfc with specific information?