Hierarchy Query For Full Tree ?

Hi Everyone,
I want to write a hierarchy query which should give me the whole path starting from root node to each individual nodes by passing value of any individual tree member. below is the sample data and the output what i am expecting. and also the output what i am getting right now from my query.
CREATE TABLE RELATION (PARENT VARCHAR2(1),CHILD VARCHAR2(1) PRIMARY KEY);
--Data for the tree which starts from the root 'A'
Insert into RELATION (PARENT, CHILD) Values (NULL,'A');
Insert into RELATION (PARENT, CHILD) Values ('A', 'B');
Insert into RELATION (PARENT, CHILD) Values ('A', 'C');
Insert into RELATION (PARENT, CHILD) Values ('B', 'D');
Insert into RELATION (PARENT, CHILD) Values ('B', 'E');
Insert into RELATION (PARENT, CHILD) Values ('D', 'F');
Insert into RELATION (PARENT, CHILD) Values ('C', 'G');
--Data for the tree which starts from the root 'H'
Insert into RELATION (PARENT, CHILD) Values (NULL,'H');
Insert into RELATION (PARENT, CHILD) Values ('H', 'I');
Insert into RELATION (PARENT, CHILD) Values ('H', 'J');
Expected Output by passing values as 'C' which gives the whole tree where the node C is present:
A
A->B
A->C
A->B->D
A->B->E
A->C->G
A->B->D->F
My Query:
select
sys_connect_by_path(child,'->') tree
from
relation
--where (parent ='C' or child='C') 
start with
parent is null
connect by
prior child = parent
order by tree;
Output of my query:
->A
->A->B
->A->B->D
->A->B->D->F
->A->B->E
->A->C
->A->C->G
->H
->H->I
->H->J
I am not able to add the condition for the query so that i can get only rows of the tree where the nod 'C' is present. i am just getting whole data from the table with all the unwanted trees.
Can anyone please help me in getting the correct output.
Thank you in advance.

odie_63 wrote:
Another solution, involving analytics : Hierarchical queries and analytic functions do not mix well together in 10g:
SQL> select * from v$version
  2  /
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
PL/SQL Release 10.2.0.4.0 - Production
CORE    10.2.0.4.0      Production
TNS for 32-bit Windows: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
SQL> SELECT tree
  2  FROM (
  3    select sys_connect_by_path(child,'->') tree,
  4           max(case when child = 'C' then connect_by_root(child) end) over() root1,
  5           connect_by_root(child) root2
  6    from relation
  7    start with parent is null
  8    connect by prior child = parent
  9  )
10  WHERE root1 = root2
11  ;
  from relation
ERROR at line 6:
ORA-00600: internal error code, arguments: [qctcte1], [0], [], [], [], [], [], []
SQL> Although it is much better in 11g:
SQL> select * from v$version
  2  /
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE    11.2.0.1.0      Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
SQL> SELECT tree
  2  FROM (
  3    select sys_connect_by_path(child,'->') tree,
  4           max(case when child = 'C' then connect_by_root(child) end) over() root1,
  5           connect_by_root(child) root2
  6    from relation
  7    start with parent is null
  8    connect by prior child = parent
  9  )
10  WHERE root1 = root2
11  ;
TREE
->A
->A->B
->A->B->D
->A->B->D->F
->A->B->E
->A->C
->A->C->G
7 rows selected.
SQL> SY.

Similar Messages

  • Query for hierarchical tree

    I am trying to build a hierarchical tree and tried various option but is unable to show the tree. I have tried using record group and also query text. When I used
    Ftree.Set_Tree_Property(htree, Ftree.query_text, 'SELECT 1, hierarchy_level, hierarchy_code, '', hierarchy_desc FROM oms_cust_hierarcy_tree_vw
    connect by prior hierarchy_code = hierarchy_parent
    start with hierarchy_parent is null');
    I got following error:
    "FRM-47313: invalid query for hierarchical tree".
    I am stuck now. Any help will be appreciated.
    Thanks
    Brinder

    dear member try this query
    SQL>
    1 SELECT level, LPAD(' ',2*level-2)||emp.ename ename, emp.empno, emp.mgr, emp.deptno
    2 FROM Emp
    3 CONNECT BY PRIOR emp.empno = emp.mgr
    4* START WITH emp.empno = 7839
    SQL> /
    LEVEL ENAME EMPNO MGR DEPTNO
    1 KING 7839 10
    2 BLAKE 7698 7839 10
    3 MARTIN 7654 7698 10
    3 ALLEN 7499 7698 10
    3 TURNER 7844 7698 10
    3 JAMES 7900 7698 10
    3 WARD 7521 7698 10
    2 CLARK 7782 7839 10
    3 MILLER 7934 7782 10
    2 JONES 7566 7839 10
    3 FORD 7902 7566 10
    4 SMITH 7369 7902 10
    5 Ken 999 7369 10
    3 SCOTT 7788 7566 10
    4 ADAMS 7876 7788 10
    M Rizwan

  • SQL Query for full paid invoices and payed out credit notes

    Hi alltogether,
    I have some problems with a sql query.
    I want to export all closed (full paid) invoices and credit notes in a table with the paid date.
    The problem is that I have several internal reconciliations for one invoice or credit note.
    So with my current query I get all these dates in the result but only for invoices, not for credit notes.
    I only need the last internal reconciliation date as payment date for all invoices and credit notes where the open amount is 0.
    In SAP B1 the finance team has service invoices and credit notes imported out of an ERP system.
    These documents are marked with an 'Y" in the coloumn "U_I_Imported" in the table "OINV" or "ORIN".
    SELECT
    OINV.DocTotal - OINV.PaidToDate as Offen, OINV.NumAtCard, OINV.U_I_Imported, ORCT.DocDate as 'Zahlungsdatum'
    SELECT
    OINV.DocTotal - OINV.PaidToDate as Offen, OINV.NumAtCard, OINV.U_I_Imported, ORCT.DocDate as 'Zahlungsdatum'
    FROM
    OJDT inner join
    ORCT on OJDT.BaseRef = ORCT.DocNum inner join
    RCT2 on ORCT.DocNum = RCT2.DocNum inner join
    OINV on RCT2.BaseAbs = OINV.DocEntry
    where
    OINV.DocTotal - OINV.PaidToDate = 0 and  OINV.U_I_Imported = 'Y'
    group by
    OINV.NumatCard, OINV.DocTotal - OINV.PaidToDate, OINV.U_I_Imported, ORCT.DocDate
    order by
    ORCT.DocDate
    I hope you can help me.
    Kind regards,
    Max

    The solution for my problem:
    select
    OINV.DocTotal - OINV.PaidToDate as 'Offen', OINV.CardCode as 'Kundennummer', OINV.NumAtCard as 'DIAMOD Rechnungsnummer', OINV.DocNum as 'Dokumentennummer',  max(ORCT.DocDate) as 'Zahlungsdatum', case when ORCT.DocCurr = (select MainCurncy from OADM) then RCT2.DcntSum else RCT2.DcntSumFC end as 'SkontoRechnungswährung',
        RCT2.DcntSum as 'SkontoFirmenwährung'
    from
        JDT1 inner join
        OJDT on JDT1.TransId = OJDT.TransId inner join
        ORCT on OJDT.BaseRef = ORCT.DocNum inner join
        RCT2 on ORCT.DocNum = RCT2.DocNum inner join
        OINV on RCT2.BaseAbs = OINV.DocEntry
    where
    JDT1.TransType in ('24') and
    OINV.U_I_Imported = 'Y' and
    OINV.DocTotal - OINV.PaidToDate = 0
    group by
    OINV.NumAtCard, OINV.DocNum, OINV.CardCode, OINV.DocTotal - OINV.PaidToDate, ORCT.DocCurr, RCT2.DcntSum, RCT2.DcntSumFC
    union all
    select
    OINV.DocTotal - OINV.PaidToDate as Offen, OINV.CardCode as 'Kundennummer', OINV.NumAtCard as 'DIAMOD Rechnungsnummer', OINV.DocNum as 'Dokumentennummer',  max(OITR.ReconDate) as 'Zahlungsdatum',
        0.0 as 'SkontoRechnungswährung',
        0.0 as 'SkontoFirmenwährung'
    from
    OITR inner join
    ITR1 on OITR.ReconNum = ITR1.ReconNum inner join
    OINV on ITR1.SrcObjAbs = OINV.DocEntry
    where
    OINV.DocTotal - OINV.PaidToDate = 0 and ITR1.SrcObjTyp = 13 and OINV.U_I_Imported = 'Y'
    group by
    OINV.NumatCard, OINV.DocNum, OINV.CardCode, OINV.DocTotal - OINV.PaidToDate
    union all
    select
    ORIN.DocTotal - ORIN.PaidToDate as Offen, ORIN.CardCode as 'Kundennummer', ORIN.NumAtCard as 'DIAMOD Rechnungsnummer', ORIN.DocNum as 'Dokumentennummer',  max(OITR.ReconDate) as 'Zahlungsdatum',
        0.0 as 'SkontoRechnungswährung',
        0.0 as 'SkontoFirmenwährung'
    from
    OITR inner join
    ITR1 on OITR.ReconNum = ITR1.ReconNum inner join
    ORIN on ITR1.SrcObjAbs = ORIN.DocEntry
    where
    ORIN.DocTotal - ORIN.PaidToDate = 0 and ITR1.SrcObjTyp = 14 and ORIN.U_I_Imported = 'Y'
    group by
    ORIN.NumatCard, ORIN.DocNum, ORIN.CardCode, ORIN.DocTotal - ORIN.PaidToDate

  • Plz help me in this query for the tree

    hi All
    I want to bulid tree that start with for example
    schema name "scott"
    then table "dept,emp
    then ename in table emp
    root scott
    parent dept
    child emp_name
    please help me in the query ?

    user222 wrote:
    any help my dearsIf you can draw one simple tree example. Then it will be easy to create query. Because i am confuse about the output. Just draw one example of your desired output tree. Then it will help to find solution.
    And while writing query or any example so use the 6 digit before and after your query or example to keep the formatting in orignal format. Otherwise it becomes hard to read.
    For more information see FAQ on right corner for page.
    -Ammad                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Query for full drives

    SQL Windows Server: 2008 R2
    SQL: 2008 R2
    Problem: I have following drives on this server, Is there a query that I can run daily which will show us the % full and remaining storage capacity on these drives?
    Logs(L)
    Data(M)
    Tempdb(T)
    I would like to run that query on all of my servers to get a daily report.
    Thanks for your help.

    Hi,
    1.
    EXEC MASTER..xp_fixeddrives
    GO
    2.
    SELECT DISTINCT dovs.logical_volume_name AS LogicalName,
    dovs.volume_mount_point AS Drive,
    CONVERT(INT,dovs.available_bytes/1048576.0) AS FreeSpaceInMB
    FROM sys.master_files mf
    CROSS APPLY sys.dm_os_volume_stats(mf.database_id, mf.FILE_ID) dovs
    ORDER BY FreeSpaceInMB ASC
    GO
    3.
    SELECT DISTINCT DB_NAME(dovs.database_id) DBName,
    mf.physical_name PhysicalFileLocation,
    dovs.logical_volume_name AS LogicalName,
    dovs.volume_mount_point AS Drive,
    CONVERT(INT,dovs.available_bytes/1048576.0) AS FreeSpaceInMB
    FROM sys.master_files mf
    CROSS APPLY sys.dm_os_volume_stats(mf.database_id, mf.FILE_ID) dovs
    ORDER BY FreeSpaceInMB ASC
    GO
    Hope will help you
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it

  • Need Hierarchial Query

    Hi All,
    I have below tables,
    Tables
    1 Employees Type (Tells About Employees Designation)
    2.Employee Details (Tells Employee Details)
    3.Employee Relation (Tells Relationship between Employees)
    Hierarchy
    ARC (SENIOR MANAGER)
    SUN (MANAGER)
    MOON (TECH LEAD)
    LITE (EMPLOYEE)
    RAG (TECH LEAD)
    BESH (TECH LEAD)
    CHESH (EMPLOYEE)
    PRASAD (EMPLOYEE)
    1 Employees Type Data
    Type No||Type Name
    1|Employee
    2|Tech Lead
    3|Manager
    4|Senior Manager
    2.Employee Details
    Emp No||Emp Name|Employee Type
    10|ARC|4
    20|SUN|3
    30|RAG|2
    40|PRASAD|1
    50|MOON|2
    60|LITE|1
    70|CHESH|1
    80|BESH|2
    3. Employee Relation
    Relation Number|Emp No|Prnt_Relation Number
    1|10|NULL
    2|20|1
    3|30|1
    4|40|1
    5|50|2
    6|60|2
    7|70|3
    8|80|3
    These are my tables structure,
    Now I want Hierarchial Query for below,
    Input will be Relation Number,
    if I give relation number as input I want to display all immediate childern that are Tech Leads and Employees only (it should ignore if it is having any Managers in the result set)
    Ex: -
    Input is relation number from Employee Relation Table,
    If I give input as *1*
    Output Should be,
    Relation Number|Employee_id|Employee Name
    3|30|Rag
    7|70|Besh
    8|80|Chesh
    If I give input as *2*
    Output Should be,
    Relation Number|Employee_id|Employee Name
    5|50|MOON
    6|60|LITE,
    If I give input as *4*
    Output Should be,
    Relation Number|Employee_id|Employee Name
    <NO Rows Returned>
    Thanks,

    Hi,
    with emp_type as (  select 1 type_id, 'Employee' emp_type from dual
    union
                        select 2 type_id, 'Tech Lead' emp_type from dual
    union
                        select 3 type_id, 'Manager' emp_type from dual
    union
                        select 4 type_id, 'Senior Manager' emp_type from dual),
    emp_details as (   select 10 emp_no, 'ARC' fname, 4 type1 from dual
    union
                            select 20 emp_no, 'SUN' fname, 3 type1 from dual
    union
                            select 30 emp_no, 'RAG' fname, 2 type1 from dual
    union
                            select 40 emp_no, 'PRASAD' fname, 1 type1 from dual
    union
                            select 50 emp_no, 'MOON' fname, 2 type1 from dual
    union
                            select 60 emp_no, 'LITE' fname, 1 type1 from dual
    union
                            select 70 emp_no, 'CHESH' fname, 1 type1 from dual
    union
                            select 80 emp_no, 'BESH' fname, 2 type1 from dual),
    Emp_Relation as (
    select 1 Relation, 10 emp_no1, null parent_Relation from dual
    union
    select 2 Relation, 20 emp_no1, 1 parent_Relation from dual
    union
    select 3 Relation, 30 emp_no1, 1 parent_Relation from dual
    union
    select 4 Relation, 40 emp_no1, 1 parent_Relation from dual
    union
    select 5 Relation, 50 emp_no1, 2 parent_Relation from dual
    union
    select 6 Relation, 60 emp_no1, 2 parent_Relation from dual
    union
    select 7 Relation, 70 emp_no1, 3 parent_Relation from dual
    union
    select 8 Relation, 80 emp_no1, 8 parent_Relation from dual)
    select  type_id, emp_type,
            emp_no, fname, relation, parent_relation
    from    EMP_DETAILS, EMP_TYPE, EMP_RELATION
    WHERE   TYPE_ID = type1
    AND     EMP_NO  = EMP_NO1
    AND     LEVEL = 2
    CONNECT BY PRIOR RELATION = PARENT_RELATION
    START WITH RELATION = :P_RELATION
    --START WITH PARENT_RELATION IS NULL -- If want to display the complete heirarchy remove comments for this line and remove "and level = 2" and  "START WITH RELATION = :P_RELATION"For p_relation = 1
       TYPE_ID EMP_TYPE           EMP_NO FNAME    RELATION PARENT_RELATION
             3 Manager                20 SUN             2               1
             2 Tech Lead              30 RAG             3               1
             1 Employee               40 PRASAD          4               1
    3 rows selected.Not sure how do you get the following and it's not clear on what basis.
    If I give input as *1*
    Output Should be,
    Relation Number|Employee_id|Employee Name
    3|30|Rag
    7|70|Besh
    8|80|CheshFor p_relation = 2
       TYPE_ID EMP_TYPE           EMP_NO FNAME    RELATION PARENT_RELATION
             2 Tech Lead              50 MOON            5               2
             1 Employee               60 LITE            6               2
    2 rows selected.For p_relation = 3
       TYPE_ID EMP_TYPE           EMP_NO FNAME    RELATION PARENT_RELATION
             1 Employee               70 CHESH           7               3
    1 row selected.For p_relation = 4
    no rows selected.Hope this helps
    Best Regards
    Arif Khadas
    Edited by: Arif Khadas on Jun 29, 2010 12:47 PM

  • Frm-47313 Invalid Query for Hierarchy tree

    Hello. i am trying to create a hierarchy tree with the following query:
    SELECT 1, level, n.name, null, hn.nde_id
    FROM cerpt_nodes n, cerpt_hierarchy_nodes hn
    WHERE n.id = hn.nde_id
    AND hn.hir_id = 1
    CONNECT BY PRIOR hn.nde_id = hn.nde_id_parent_of
    START WITH hn.ntp_code='ROOT';
    I check the table and column names, they are correct. I tried to create tree with scott.emp table, I have no problem. The only different is this query has nested tables and where clause. Is that I cannot use WHERE clause and nested tables? Can anybody tell me what I have done wrong? Thank you very much

    I had problems with joins in the same SQL statement using the Connect Prior By statement. Try creating a view over your nested tables then create the SQL statement for the tree using the view.
    I ended up having a lot of problems using the tree control. I ended up modifing my database design to accomodate the short falls of the Connect Prior By statement.
    Hope this helps.
    Jamie

  • QUERY FOR CUSTOMERS FULL DEBIT AND CREDIT WITH CLOSING BALANCE

    Hi Friends,
       I need query for CUSTOMERS FULL DEBIT AND CREDIT WITH CLOSING BALANCE for selection criteria from date and to date.
       I know the Trial Balance Report will sort out this issue... but i need routeday wise report
    1. Business Partner Master Data - i created one UDF field called U_Routeday (MONDAY, TUESDAY, WEDNESDAY,THURSDAY,FRIDAY)
    2. The query should be like selection criteria 
                                  - Routeday [%0]
                                  - Posting Date [%1]                           
                                  - Posting Date [%2]
    CardCode
    Debit
    Credit
    Balance
    D10503
    25031.50
    24711.50
    2962.00
    D10641
    5466.00
    7460.00
    285.00
    D10642
    2866.00
    142.00
    give any helpful query ASAP... Thanks in advance

    Hi,
    Try this query:
    Declare
    @fromdate as datetime
    Declare
    @Todate as datetime
    Declare
    @Code as nvarchar(25)
    set
    @fromdate = ( select min(Ta.[RefDate]) from OJDT ta where
    Ta.[RefDate] >= [%0])
    set
    @Todate = ( select max(Tb.[RefDate]) from OJDT tb where Tb.[RefDate]
    <= [%1])
    set
    @code = (select max(Tc.[ShortName]) from JDT1 tC where Tc.[ShortName]
    = [%2])
    SELECT
    [Name] as AcctName, [Jan]= sum([1]), [Feb]= sum([2]), [Mar]=
    sum([3]), [Apr]= sum([4]),  [May]= sum([5]), [June]= sum([6]),
    [July]= sum([7]), [Aug]= sum([8]), [Sept]= sum([9]), [Oct]=
    sum([10]), [Nov]= sum([11]), [Dec]= sum([12]), total = sum
    (isnull([1],0)+ isnull([2],0) + isnull([3],0) + isnull([4],0) +
    isnull([5],0) + isnull([6],0) + isnull([7],0) + isnull([8],0) +
    isnull([9],0)+ isnull([10],0) + isnull([11],0) + isnull([12],0))
    from
    (SELECT
    T0.[ShortName] as Name, sum(T0.[Debit]-T0.[Credit]) as T,
    month(T2.[RefDate]) as month FROM JDT1 T0  INNER JOIN OACT T1 ON
    T0.Account = T1.AcctCode INNER JOIN OJDT T2 ON T0.TransId =
    T2.TransId WHERE T2.[RefDate] between @fromdate and @todate and
    T0.[ShortName]  = @code  GROUP BY T0.[ShortName],T2.[RefDate] ) S
    Pivot
    (sum(T)
    For  Month IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
    group
    by [Name],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12]
    Let me know your result.
    Thanks & Regards,
    Nagarajan

  • Query for spesific children in a tree structure

    Hi,
    My data is organized in a tree structure.
    I need a sql statement that returns a parent that
    have a set of children corresponding to some demands.
    I provide a very simplified description of my data, but it covers my problem.
    Can anyone please help me write a select statement that gives me all featureids
    that have a GID attribute with children GNR=123 AND BNR=456?
    Regards
    gv
    create table attributetype( id number, name varchar2(8), parentid number );
    insert into attributetype( id, name ) values ( 1, 'GIDLIST' );
    insert into attributetype( id, name, parentid ) values ( 2, 'GID', 1 );
    insert into attributetype( id, name, parentid ) values( 3, 'GNR', 2 );
    insert into attributetype( id, name, parentid ) values ( 4, 'BNR', 2 );
    create table attribute( featureid number, id number, parentid number, atttypeid number, intvalue number );
    --attributes for feature1
    insert into attribute( featureid, id, parentid, atttypeid ) values( 1, 1, 0, 1 );
    insert into attribute( featureid, id, parentid, atttypeid ) values( 1, 2, 1, 2 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 1, 3, 2, 3, 123 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 1, 4, 2, 4, 456 );
    insert into attribute( featureid, id, parentid, atttypeid ) values( 1, 5, 1, 2 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 1, 6, 5, 3, 12 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 1, 7, 5, 4, 456 );
    --attributes for feature 2
    insert into attribute( featureid, id, parentid, atttypeid ) values( 2, 8, 0, 1 );
    insert into attribute( featureid, id, parentid, atttypeid ) values( 2, 9, 8, 2 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 2, 10, 9, 3, 678 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 2, 11, 9, 4, 456 );
    insert into attribute( featureid, id, parentid, atttypeid ) values( 2, 12, 8, 2 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 2, 13, 12, 3, 876 );
    insert into attribute( featureid, id, parentid, atttypeid, intvalue ) values( 2, 14, 12, 4, 456 );
    commit;
    column name format a15
    select a.featureid featureid, lpad(' ', (level - 1) * 2) || b.name name, a.id attid, a.parentid parentid, a.intvalue
    from attribute a, attributetype b
    where a.atttypeid=b.id
    connect by prior a.id=a.parentid
    start with a.parentid=0;
    FEATUREID NAME ATTID PARENTID INTVALUE
    1 GIDLIST 1 0
    1 GID 2 1
    1 GNR 3 2 123
    1 BNR 4 2 456
    1 GID 5 1
    1 GNR 6 5 12
    1 BNR 7 5 456
    2 GIDLIST 8 0
    2 GID 12 8
    2 GNR 13 12 876
    2 BNR 14 12 456
    2 GID 9 8
    2 GNR 10 9 678
    2 BNR 11 9 456

    Hi,
    Thanks for providing the CREATE TABLE and INSERT statements; that helps a lot.
    You want featureids that meet three criteria:
    (1) there is a GID attribute
    (2) the GID attribute has a GNR child with intvalue=123
    (3) the GID attribute has a BNR child with intvalue=456
    Since you're looking for immediate children, not distant descendants, it's easiest to do this with a non-hierarrchical query that finds one of these criteria, and does EXISTS sub-queries to test for the other two.
    For example:
    WITH aat AS
    ( -- Begin aat: join of attribute and attributetype
         SELECT     a.featureid
         ,     a.id
         ,     a.parentid
         ,     a.intvalue
         ,     t.name
         FROM     attribute     a
         JOIN     attributetype     t     ON     a.atttypeid     = t.id
    ) -- End aat: join of attribute and attributetype
    SELECT DISTINCT     featureid
    FROM     aat     m     -- m for main
    WHERE     name     = 'GID'
    AND     EXISTS     (     -- Begin EXISTS sub-query for GNR=123
              SELECT     NULL
              FROM     aat
              WHERE     parentid     = m.id
              AND     name          = 'GNR'
              AND     intvalue     = 123
              )     -- End EXISTS sub-query for GNR=123
    AND     EXISTS     (     -- Begin EXISTS sub-query for BNR=456
              SELECT     NULL
              FROM     aat
              WHERE     parentid     = m.id
              AND     name          = 'BNR'
              AND     intvalue     = 456
              )     -- End EXISTS sub-query for BNR=456
    ;Alternatively, you could do a three-way self join, and skip the EXISTS sub-queries.
    If you were looking for GNR and BNR descendants, any number of levels below the same GID node, it's easy to modify the query above. Just re-write the EXISTS sub-queries to CONNECT BY queries that "START WITH parentid = m.id".
    It looks like this application will have a lot of use for a view like aat, above. If you don't already have a permanent view like that, you should create one.

  • Query for Position Hierarchy

    Hi friends,
    I need urgent help. I have tried that Position Hierarchy query. If i give Bottom position id and Top position id , it should display that particular root only.
    This is my query.
    SELECT posname, subordinate_position_id, parent_position_id
    FROM (
    SELECT SYS_CONNECT_BY_PATH (pse.subordinate_position_id, '/') posname,
    pse.subordinate_position_id, parent_position_id
    FROM (SELECT NAME, position_id
    FROM hr_all_positions_f_tl
    WHERE LANGUAGE = USERENV ('LANG')) hap,
    (SELECT NAME, position_id
    FROM hr_all_positions_f_tl
    WHERE LANGUAGE = USERENV ('LANG')) has,
    per_pos_structure_elements pse
    WHERE pse.business_group_id = 0
    AND hap.position_id = pse.parent_position_id
    AND has.position_id = pse.subordinate_position_id
    START WITH pse.parent_position_id = 63--:parent_posid
    CONNECT BY PRIOR pse.subordinate_position_id = pse.parent_position_id
    AND PRIOR pse.pos_structure_version_id = pse.pos_structure_version_id
    WHERE subordinate_position_id = 362--:subposid
    Output coming like this :
    Posname SUBORDINATE_POSITION_ID                 PARENT_POSITION_ID
    /81/55/161/135/188/141/101/362 *362 101*
    It returns one row only
    i need Like this
    subordinate positiond_id Parent_position_id
    362 101
    101 141
    141 188
    188 135
    135 161
    161 55
    55 81
    81 63.
    How to achieve this.. Please help.
    Thanks in advance.
    Kavi

    Try this
    SELECT null posname, subordinate_position_id, parent_position_id, level_num
    FROM (
    SELECT distinct
    --SYS_CONNECT_BY_PATH (pse.subordinate_position_id, '/') posname, --uncomment this line if necessary
    level level_num,
    pse.subordinate_position_id, parent_position_id
    FROM (SELECT NAME, position_id
    FROM hr_all_positions_f_tl
    WHERE LANGUAGE = USERENV ('LANG')) hap,
    (SELECT NAME, position_id
    FROM hr_all_positions_f_tl
    WHERE LANGUAGE = USERENV ('LANG')) has,
    per_pos_structure_elements pse
    WHERE pse.business_group_id = 0
    AND hap.position_id = pse.parent_position_id
    AND has.position_id = pse.subordinate_position_id
    START WITH pse.parent_position_id = 63--:parent_posid
    CONNECT BY PRIOR pse.subordinate_position_id = pse.parent_position_id
    AND PRIOR pse.pos_structure_version_id = pse.pos_structure_version_id
    WHERE subordinate_position_id = 362--:subposid
    order by level_numMake sure that the you are using the correct values for the 3 IDs.
    Hope this helps,
    Sandeep Gandhi

  • Query for the FULL AND FINAL SETTLEMENT REPORT

    Hi,  any one  has the query for the FULL AND FINAL SETTLEMENT REPORT in oracle hrms??

    Hi,
    I go through that .class file and find that they have used below package in that.
    PAY_IN_TERM_RPRT_GEN_PKG
    Hope this will help you.

  • "db file scattered read" too high and Query going for full table scan-Why ?

    Hi,
    I had a big table of around 200mb and had a index on it.
    In my query I am using the where clause which has to use the
    index. I am neither using any not null condition
    nor using any function on the index fields.
    Still my query is not using the index.
    It is going for full table scan.
    Also the statspack report is showing the
    "db file scattered read" too high.
    Can any body help and suggest me why this is happenning.
    Also tell me the possible solution for it.
    Thanks
    Arun Tayal

    "db file scattered read" are physical reads/multi block reads. This wait occurs when the session reading data blocks from disk and writing into the memory.
    Take the execution plan of the query and see what is wrong and why the index is not being used.
    However, FTS are not always bad. By the way, what is your db_block_size and db_file_multiblock_read_count values?
    If those values are set to high, Optimizer always favour FTS thinking that reading multiblock is always faster than single reads (index scans).
    Dont see oracle not using index, just find out why oracle is not using index. Use the INDEX hint to force optimizer to use index. Take the execution with/witout index and compare the cardinality,cost and of course, logical reads.
    Jaffar
    Message was edited by:
    The Human Fly

  • Need to write SQL query for hierarchy

    Hi Guys,
    I need help to write a query for the below scenario.
    I have one organization, under that I have many branches. when i provide input to query on last branch, i need to display all parents of that branch like below
    Organization   ---parent
      branch 1  ---child
         branch11
         branch 12
        branch 2   ---child
          branch 21
         branch 3 ----child
          branch 31
          branch 32
          branch 33
    here, when i provide input as branch 3, then I need to fetch results branch 2, branch 1 till organization.
    can any one help me on this.
    Thanks in advance!
    Regards,
    LKR

    Hi,
    Is this the same question as
    https://community.oracle.com/thread/2616828
    Please don't post the same question over and over.  Mark this thread as "Answered" right away, and continue in the other thread (if necessary; the other thread has answers.)

  • Error while executing a sql query for select

    HI All,
    ORA-01652: unable to extend temp segment by 128 in tablespace PSTEMP i'm getting this error while i'm executing the sql query for selecting the data.

    I am having 44GB of temp space, while executing the below query my temp space is getting full, Expert please let us know how the issue can be resolved..
    1. I dont want to increase the temp space
    2. I need to tune the query, please provide your recomendations.
    insert /*+APPEND*/ into CST_DSA.HIERARCHY_MISMATCHES
    (REPORT_NUM,REPORT_TYPE,REPORT_DESC,GAP,CARRIED_ITEMS,CARRIED_ITEM_TYPE,NO_OF_ROUTE_OF_CARRIED_ITEM,CARRIED_ITEM_ROUTE_NO,CARRIER_ITEMS,CARRIER_ITEM_TYPE,CARRIED_ITEM_PROTECTION_TYPE,SOURCE_SYSTEM)
    select
    REPORTNUMBER,REPORTTYPE,REPORTDESCRIPTION ,NULL,
    carried_items,carried_item_type,no_of_route_of_carried_item,carried_item_route_no,carrier_items,
    carrier_item_type,carried_item_protection_type,'PACS'
    from
    (select distinct
    c.REPORTNUMBER,c.REPORTTYPE,c.REPORTDESCRIPTION ,NULL,
    a.carried_items,a.carried_item_type,a.no_of_route_of_carried_item,a.carried_item_route_no,a.carrier_items,
    a.carrier_item_type,a.carried_item_protection_type,'PACS'
    from CST_ASIR.HIERARCHY_asir a,CST_DSA.M_PB_CIRCUIT_ROUTING b ,CST_DSA.REPORT_METADATA c
    where a.carrier_item_type in('Connection') and a.carried_item_type in('Service')
    AND a.carrier_items=b.mux
    and c.REPORTNUMBER=(case
    when a.carrier_item_type in ('ServicePackage','Service','Connection') then 10
    else 20
    end)
    and a.carrier_items not in (select carried_items from CST_ASIR.HIERARCHY_asir where carried_item_type in('Connection') ))A
    where not exists
    (select *
    from CST_DSA.HIERARCHY_MISMATCHES B where
    A.REPORTNUMBER=B.REPORT_NUM and
    A.REPORTTYPE=B.REPORT_TYPE and
    A.REPORTDESCRIPTION=B.REPORT_DESC and
    A.CARRIED_ITEMS=B.CARRIED_ITEMS and
    A.CARRIED_ITEM_TYPE=B.CARRIED_ITEM_TYPE and
    A.NO_OF_ROUTE_OF_CARRIED_ITEM=B.NO_OF_ROUTE_OF_CARRIED_ITEM and
    A.CARRIED_ITEM_ROUTE_NO=B.CARRIED_ITEM_ROUTE_NO and
    A.CARRIER_ITEMS=B.CARRIER_ITEMS and
    A.CARRIER_ITEM_TYPE=B.CARRIER_ITEM_TYPE and
    A.CARRIED_ITEM_PROTECTION_TYPE=B.CARRIED_ITEM_PROTECTION_TYPE
    AND B.SOURCE_SYSTEM='PACS'
    Explain Plan
    ==========
    Plan
    INSERT STATEMENT ALL_ROWSCost: 129 Bytes: 1,103 Cardinality: 1                                                        
         20 LOAD AS SELECT CST_DSA.HIERARCHY_MISMATCHES                                                   
              19 PX COORDINATOR                                              
                   18 PX SEND QC (RANDOM) PARALLEL_TO_SERIAL SYS.:TQ10002 :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1                                         
                        17 NESTED LOOPS PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1                                    
                             15 HASH JOIN RIGHT ANTI NA PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,098 Cardinality: 1                               
                                  4 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 63 Bytes: 359,283 Cardinality: 15,621                          
                                       3 PX SEND BROADCAST PARALLEL_TO_PARALLEL SYS.:TQ10001 :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621                     
                                            2 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621                
                                                 1 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621           
                                  14 NESTED LOOPS ANTI PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 40,256,600 Cardinality: 37,448                          
                                       11 HASH JOIN PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 6,366,160 Cardinality: 37,448                     
                                            8 BUFFER SORT PARALLEL_COMBINED_WITH_CHILD :Q1002               
                                                 7 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 1 Bytes: 214 Cardinality: 2           
                                                      6 PX SEND BROADCAST PARALLEL_FROM_SERIAL SYS.:TQ10000 Cost: 1 Bytes: 214 Cardinality: 2      
                                                           5 INDEX FULL SCAN INDEX CST_DSA.IDX$$_06EF0005 Cost: 1 Bytes: 214 Cardinality: 2
                                            10 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448                
                                                 9 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448           
                                       13 TABLE ACCESS BY INDEX ROWID TABLE PARALLEL_COMBINED_WITH_PARENT CST_DSA.HIERARCHY_MISMATCHES :Q1002Cost: 0 Bytes: 905 Cardinality: 1                     
                                            12 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT SYS.HIERARCHY_MISMATCHES_IDX3 :Q1002Cost: 0 Cardinality: 1                
                             16 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT CST_DSA.IDX$$_06EF0001 :Q1002Cost: 1 Bytes: 5 Cardinality: 1

  • Links for navigation tree not rendering as expected

    I have a tree menu that links to various applications. It provides single sign-on to different applications for intranet users, passing encrypted authentication details between apps. The tree table is defined as:
    APPLICATION_ID NUMBER(10),
    APPLICATION_NAME VARCHAR2(50),
    LOCATION VARCHAR2(500),
    PARENT_APPLICATION_ID NUMBER(10),
    SHOW VARCHAR2(1)
    The location column provides the link for the tree. Here is an example of one record:
    set escape ~
    insert into application_menu_tree
    values (2, 'Application Name',
    'f?p=100:102:::NO::P101_USERNAME,P101_PASSWORD,MENU_SESSION:~&MENU_USERNAME.,~&MENU_PASSWORD.,~&APP_SESSION.',
    1,
    NULL);
    This works without a problem in the full version of APEX/10gR2/Oracle App Server. Mouse over a link and you see the &APP_USERRNAME. replaced with the encrypted version of the username. Same with the rest.
    Export/import into XE though and the link doesn't pick up the &MENU_USERNAME., &MENU_PASSWORD., or &APP_SESSION. when rendering the menu. A mouse-over of the link shows those values are not being replaced in the string, but if I pull the session values using the Edit links, all are populated just fine.
    If I copy that same string (the one that is used for the link in the tree), and paste it directly to an html region as an href, the variables are replaced as expected and the link works just fine.
    So, a link pulled from the table doesn't have those values replaced, where the same string in an html region as an href does just fine. The table method does work in the full version, but doesn't in two installs of XE (same page definition - export/import).
    Any ideas?
    Thanks,
    Ron

    Did you change anything when moving the application to XE, or did you just a plain export/import? Plain export/import except the choice of theme- was using 16 in 2.2 and changed to an XE supplied theme.
    You exported the application using UTF8 and imported it using UTF8 as well, right? Yep
    Which version of XE are you using, the Western European Edition or the Universal one?Universal
    What was the exact select statement and what type of region did you use? The tree query is about as straight forward as can be:
    select "APPLICATION_ID" id,
    "PARENT_APPLICATION_ID" pid,
    "APPLICATION_NAME" name,
    location link,
    null a1,
    null a2
    from "#OWNER#"."APPLICATION_MENU_TREE"
    Was it the same in XE and Apex 2.2.1?Yep - no difference in data or query, and the page is exactly the same except for the application theme.
    I just modified the query to do the replacement instead and that's working just fine in XE. New query:
    select "APPLICATION_ID" id,
    "PARENT_APPLICATION_ID" pid,
    "APPLICATION_NAME" name,
    REPLACE(
    REPLACE(
    REPLACE(location, '#APP_SESSION#', :app_session),
    '#MENU_USERNAME#', :menu_username),
    '#MENU_PASSWORD#', :menu_password) link,
    null a1,
    null a2
    from "#OWNER#"."APPLICATION_MENU_TREE"
    I'll post an example of what I'd set up before to the Oracle hosted APEX when I get a chance and toss the link here. Being 2.2.1 it should work there as well.
    Thanks again for the suggested change!
    Ron

Maybe you are looking for