Hierarchy query and number of subnodes

Hi all,
I've been struggling with this: is there a possibility to select the number of subnodes of a banch? the only way I can think of is this:
select id, desc, (select count(*) from table b connect by prior id=parent_id start with b.parent_id =a.id )
from table a
connect by prior id=parent_id
start with parent_id is null
order siblings by idbut I wonder if this is the way to go or there's a more simple/faster way to do this.
Thanks in advance for any help! This query is executed on Oracle 10gr2 and up!

Hi Aketi,
Thanks for your queries. But the query from Tubby is still faster then yours, I'm sorry!
Here's the explain-plan for your query:
PLAN_TABLE_OUTPUT                                                                             
| Id  | Operation                       | Name          | Rows  | Bytes |TempSpc| Cost (%CPU)|
|   0 | SELECT STATEMENT                |               |   221 |   465K|       |   111   (1)|
|   1 |  SORT ORDER BY                  |               |   221 |   465K|  1192K|   111   (1)|
|   2 |   SQL MODEL ORDERED             |               |   221 |   465K|       |   111   (1)|
|   3 |    VIEW                         |               |   221 |   465K|       |     9   (0)|
|*  4 |     CONNECT BY WITHOUT FILTERING|               |       |       |       |            |
|*  5 |      TABLE ACCESS FULL          | FZENNAVIGATOR |     1 |    55 |       |     9   (0)|
|   6 |      TABLE ACCESS FULL          | FZENNAVIGATOR |   221 | 11050 |       |     9   (0)|
Predicate Information (identified by operation id):                                           
   4 - access("NAV_NAV_PK"=PRIOR "NAV_PK")                                                    
   5 - filter("NAV_NAV_PK" IS NULL)     And the explain plan for Tubby's query:
PLAN_TABLE_OUTPUT                                                                    
| Id  | Operation                      | Name          | Rows  | Bytes | Cost (%CPU)|
|   0 | SELECT STATEMENT               |               |   221 | 31382 |    10  (10)|
|   1 |  SORT GROUP BY                 |               |   221 | 31382 |    10  (10)|
|   2 |   VIEW                         |               |   221 | 31382 |     9   (0)|
|*  3 |    CONNECT BY WITHOUT FILTERING|               |       |       |            |
|   4 |     TABLE ACCESS FULL          | FZENNAVIGATOR |   221 | 11050 |     9   (0)|
Predicate Information (identified by operation id):                                  
   3 - access("NAV_NAV_PK"=PRIOR "NAV_PK")                                            When I execute your query in a loop 1000x, it ran for 231 secs, the first query in a loop 1000x ran for 4,6 secs!

Similar Messages

  • Hierarchy query and analytical functions

    Hi I have 2 tables which are
    ACCOUNT TBL
    ACCOUNT_ID        PAYING_ACCOUNT_ID           PARENT_ACCOUNT_ID
    4571111               4571111                    4571111  
    4571112               4571112                    4571111
    4571113               4571113                    4571111
    3995313               3995313                    3995313
    3996786               3995313                    3995313
    4008375               3995313                    3995313CUSTOMER_STATUS
    CUSTOMER_ID        CUSTOMER_STATUS
    4571111                Active  
    4571112                Active      
    4571113                Active      
    3995313                Active    
    3996786                Deactive      
    4008375                Active       I need to produce an output like below:
    Level_Label            ACCOUNT_ID       PAYING_ACCOUNT_ID    PARENT_ACCOUNT_ID    MY_TOTAL_PR_A   MY_TOTAL_NPR_A   TOTAL_PR_A   TOTAL_NPR_A     MY_TOTAL_PR_D       MY_TOTAL_NPR_D      TOTAL_PR_D      TOTAL_NPR_D
    3995313                  3995313             3995313              3995313               0            1               0            1                  0                 1                   0               1
          4008375            4008375             3995313              3995313               0            0               0            1                  0                 0                   0               1
          3996786            3996786             3995313              3995313               0            0               0            1                  0                 0                   0               1
    4571111                  4571111             4571111              4571111               2            0               2            0                  0                 0                   0               0
          4571112            4571112             4571112              4571111               0            0               2            0                  0                 0                   0               0
          4571113            4571113             4571113              4571111               0            0               2            0                  0                 0                   0               0This is the logic and rational to fill-up above fields.
    MY_TOTAL_PR_A            Sum of all child accounts of current account that are PR (PAYING_ACCOUNT_ID = ACCOUNT_ID) and in sates considered Active.
                                         The current account is not included in the sum, only child accounts
    MY_TOTAL_NPR_A          Sum of all child accounts of current account that are NPR (PAYING_ACCOUNT_ID != ACCOUNT_ID)  and in sates considered Active.
                                         The current account is not included in the sum, only child accounts
    TOTAL_PR_A                  Sum of all accounts of the structure that are PR and in sates considered Active.
                                         The TOP account is not included in the sum, only TOP account childs
    TOTAL_NPR_A                Sum of all accounts of the structure that are NPR and in sates considered Active.
                                         The TOP account is not included in the sum, only TOP account childs
    MY_TOTAL_PR_D            Sum of all child accounts of current account that are PR and in sates considered Deactive.
                                         The current account is not included in the sum, only child accounts
    MY_TOTAL_NPR_D          Sum of all child accounts of current account that are NPR and in sates considered Deactive.
                                          The current account is not included in the sum, only child accounts
    TOTAL_PR_D                Sum of all accounts of the structure that are PR and in sates considered Deactive.
                                          The TOP account is not included in the sum, only TOP account childs
    TOTAL_NPR_D              Sum of all accounts of the structure that are NPR and in sates considered Deactive.
                                           The TOP account is not included in the sum, only TOP account childsThis is my code, I managed to calculate the MY_TOTAL_XXX filed but failed to calculate TOTAL_XXX. Appreciate any information / comment. Thanks
    WITH     got_descendants          AS
         SELECT     CONNECT_BY_ROOT a.account_id     AS ancestor_id
         ,     a.paying_account_id
      ,  a.account_id
      , a.parent_account_id
         ,     LEVEL                    AS lvl
      , c.customer_status
         FROM     account a inner join customer_status c
      on a.account_id = c.customer_id
         CONNECT BY NOCYCLE     PRIOR a.account_id     = a.parent_account_id
              --AND          account_id          != parent_account_id
    ), DUMMY2 AS
    select g.*  from got_descendants g
    ), DUMMY AS
    SELECT       ancestor_id
    ,       COUNT (CASE WHEN lvl             > 1
                      AND  account_id  = paying_account_id
                And  ancestor_id != account_id
                AND  customer_status = 'A' THEN 1 END)     AS my_total_pr_a
    ,       COUNT (CASE WHEN ancestor_id  = paying_account_id
               AND  customer_status = 'A' THEN 1 END)     AS total_pr_a
    ,       COUNT (CASE WHEN lvl             > 1
                      AND  account_id != paying_account_id
                And  ancestor_id != account_id
                AND  customer_status = 'A' THEN 1 END)     AS my_total_npr_a
    ,       COUNT (CASE WHEN ancestor_id != paying_account_id
               AND  customer_status = 'A'
               And  ancestor_id != parent_account_id THEN 1 END)     AS total_npr_a
    ,       COUNT (CASE WHEN lvl             > 1
                      AND  account_id  = paying_account_id
                And  ancestor_id != account_id
                AND  customer_status = 'D' THEN 1 END)     AS my_total_pr_d
    ,       COUNT (CASE WHEN ancestor_id  = paying_account_id
               AND  customer_status = 'D' THEN 1 END)     AS total_pr_d
    ,       COUNT (CASE WHEN lvl             > 1
                      AND  account_id != paying_account_id
                And  ancestor_id != account_id
                AND  customer_status = 'D' THEN 1 END)     AS my_total_npr_d
    ,       COUNT (CASE WHEN ancestor_id != paying_account_id
               AND  customer_status = 'D' THEN 1 END)     AS total_npr_d
    FROM       DUMMY2
    GROUP BY ancestor_id
    SELECT  lpad(' ', 2*level) || ACCOUNT.ACCOUNT_ID AS LEVEL_LABEL, LEVEL, CONNECT_BY_ISCYCLE "Cycle",
    ACCOUNT.PAYING_ACCOUNT_ID, ACCOUNT.PARENT_ACCOUNT_ID, ACCOUNT.ACCOUNT_ID,
    DUMMY.my_total_pr_a, DUMMY.total_pr_a, DUMMY.my_total_npr_a, DUMMY.total_npr_a,
    DUMMY.my_total_pr_d, DUMMY.total_pr_d, DUMMY.my_total_npr_d, DUMMY.total_npr_d
    from ACCOUNT INNER JOIN DUMMY  ON  ACCOUNT.account_id = DUMMY.ancestor_id
    START WITH ACCOUNT.parent_account_id = ACCOUNT.account_id 
    CONNECT BY NOCYCLE PRIOR ACCOUNT.account_id = ACCOUNT.parent_account_idDDL
    CREATE TABLE ACCOUNT
        "CUSTOMER_ID"       NUMBER(20,0) NOT NULL ENABLE,
        "PAYING_ACCOUNT_ID" NUMBER(20,0),
        "PARENT_ACCOUNT_ID" NUMBER(20,0),
        "ACCOUNT_ID"        NUMBER,
        "COMPANY_ID"        NUMBER
    CREATE TABLE CUSTOMER_STATUS
        "CUSTOMER_ID"     NUMBER(10,0),
        "CUSTOMER_STATUS" VARCHAR2(1 BYTE)
    Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (4571111,4571111,4571111);
    Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (4571112,4571112,4571111);
    Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (4571113,4571113,4571111);
    Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (3996786,3995313,3995313);
    Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (4008375,3995313,3995313);
    Insert into ACCOUNT (ACCOUNT_ID,PAYING_ACCOUNT_ID,PARENT_ACCOUNT_ID) values (3995313,3995313,3995313);
    Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (3996786,'D');
    Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (4008375,'A');
    Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (3995313,'A');
    Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (4571111,'A');
    Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (4571112,'A');
    Insert into CUSTOMER_STATUS (CUSTOMER_ID,CUSTOMER_STATUS) values (4571113,'A');

    Hi thanks for your information and explanation..
    To answer your doubt, below explain the rational
    The logic for TOTAL_XXX
    for instance, I've picked only below data to explain the rational
    Account_id            Paying_account             Parent_account        status
    3995313               3995313                    3995313                Active
    3996786               3995313                    3995313                Deactivated
    4008375               3995313                    3995313                Active
    Showing accounts relations, status, PR\NPR, and hierarchy we have
    Account 3995313 (PR, Active)
        - Account 3996786  (NPR, Deactive)
        - Account 4008375  (NPR,   Active)
    TOTAL_PR_ACCOUNTS_A   - Sum of all accounts of the structure that are PR and in sates considered Active.
                            The TOP account is not included in the sum, only TOP account childs
    For account 3995313 the TOTAL_PR_ACCOUNTS_A is 0 (Based on the definiton, to calculate TOTAL_PR_ACCOUNTS_A, we need go throught the entire structure for that
                                                      account. In this case, we have 3995313, 3996786 and 4008375. Now we go the this three account one by one
                                               first is 3995313, this account is a TOP account in the entire structure, so is not included in the sum.
                                               second is 3996786, this account is not a TOP account therefore should be included in the sum, however this account is NPR and Deactive, so is disqualify.
                                                     third is 4008375, this account is not a TOP account and is active account therefore should be included in the sum, however this account is NPR so is disqualify.)
    For account 3996786 the TOTAL_PR_ACCOUNTS_A is 0 ( the definiton is exactly same as the above)
    For account 4008375 the TOTAL_PR_ACCOUNTS_A is 0 ( the definiton is exactly same as the above)
    For account 3995313 the TOTAL_NPR_ACCOUNTS_A is 1 (Based on the definiton, to calculate TOTAL_NPR_ACCOUNTS_A, we need go throught the entire structure for that
                                                      account. In this case, we have 3995313, 3996786 and 4008375. Now we go the this three account one by
                                                      first is 3995313, this account is a TOP account in the entire structure, so is not included in the sum.
                                                      second is 3996786, this account is not a TOP account and is NPR therefore should be included in the sum, however this account is Deactive, so is disqualify. 
                                                      third is 4008375, this account is not a TOP account and is active and NPR account therefore should be included in the sum, so is disqualify.)
    For account 3996786 the TOTAL_PR_ACCOUNTS_A is 1 ( the definiton is exactly same as the above)
    For account 4008375 the TOTAL_PR_ACCOUNTS_A is 1 ( the definiton is exactly same as the above)After execute the code as provided, seems the result was correct but I need more times to verify as I have a milions of records in the DB.
    I tried to modify the code to have better performance , but failed to process, Appreciate any help :)
    WITH    got_descendants        AS
        SELECT    CONNECT_BY_ROOT a.account_id        AS ancestor_id
        ,    CONNECT_BY_ROOT a.parent_account_id    AS parent_account_id    -- *****  NEW  *****
        ,    a.paying_account_id
        ,    a.account_id
        ,    c.customer_status
        ,    LEVEL                    AS lvl
        ,    CONNECT_BY_ISCYCLE            AS cycle
        ,    CASE
                WHEN  CONNECT_BY_ROOT a.account_id
                    = CONNECT_BY_ROOT a.parent_account_id
                THEN  ROWNUM
            END                    AS r_num
          FROM  account a inner join customer_status c
      on a.account_id = c.customer_id
        CONNECT BY NOCYCLE    PRIOR a.account_id    = a.parent_account_id
            AND        a.account_id        != a.parent_account_id
        ORDER SIBLINGS BY    a.account_id    -- Optional
    ,    got_o_num    AS
        SELECT    got_descendants.*
        ,    MIN (r_num) OVER (PARTITION BY  account_id)    AS o_num
        ,    MAX (lvl)   OVER (PARTITION BY  account_id)     AS max_lvl
        FROM    got_descendants
    ),    dummy    AS
        SELECT      ancestor_id
        ,      COUNT ( CASE WHEN lvl            > 1
                               AND  account_id        = paying_account_id
                               AND  ancestor_id       != account_id
                               AND  customer_status     = 'Active'
                       THEN 1
                   END
                )    AS my_total_pr_a
        ,      COUNT (CASE WHEN lvl            > 1
                    AND  account_id != paying_account_id
                          And  ancestor_id != account_id
                          AND  customer_status = 'Active' THEN 1 END)    AS my_total_npr_a
        ,      COUNT (CASE WHEN lvl            > 1
                    AND  account_id  = paying_account_id
                          And  ancestor_id != account_id
                          AND  customer_status = 'Deactive' THEN 1 END)    AS my_total_pr_d
        ,      COUNT (CASE WHEN lvl            > 1
                    AND  account_id != paying_account_id
                          And  ancestor_id != account_id
                          AND  customer_status = 'Deactive' THEN 1 END)    AS my_total_npr_d
    FROM      got_o_num
    GROUP BY  ancestor_id
    --select o_num from dummy
    SELECT      LPAD ( ' '
               , 2 * (MIN (max_lvl) - 1)
               )  || ancestor_id                AS level_label
    ,      MIN (max_lvl)                      AS "Level"
    ,      MIN (cycle)                        AS "Cycle"
    ,      ancestor_id                        AS account_id        -- *****  NEW  *****
    ,      MIN (paying_account_id)                     AS paying_account
    ,      MIN (parent_account_id)                AS parent_account_id    -- *****  NEW  *****
    ,    dummy.my_total_pr_a
    ,    CONNECT_BY_ROOT dummy.my_total_pr_a        AS total_pr_a
    ,    dummy.my_total_npr_a
    ,    CONNECT_BY_ROOT dummy.my_total_npr_a        AS total_npr_a
    ,    dummy.my_total_pr_d
    ,    CONNECT_BY_ROOT dummy.my_total_pr_d        AS total_pr_d
    ,    dummy.my_total_npr_d
    ,    CONNECT_BY_ROOT dummy.my_total_npr_d        AS total_npr_d
    FROM      dummy
    GROUP BY ancestor_id
    ORDER BY  MIN (o_num)

  • Using different hierarchy in a query and last value error

    Hi guys,
    there is a hierarchy for customers in the 0Customer Infoobject which I should use in my query.
    I have activated the hierarchy in the query and now some results are not appearing but red crosses "x" are shown.
    And the error message: The function Calculate Results as ... could not be applied everywhere.
    I know that I am using the result as "last value" for some columns because I need them there (for example: to determine the last value for the credit limit of the current month). I think these columns where I am using the last value calculation are only affected.
    I mean my query has a lot of characteristics and key figures and I was told that a hiearchy for customers which is available should be used. But now there are these red crosses.
    I don´t see any other solution as not to use this specific hierarchy.
    Has anybody a suggestion what could be an argument to use or not to use a hierarchy?
    Is it sometimes like in my case that a hierarchy is not possible to use?
    Thanks in advance!

    Hi,
    say for example your customer hierarchy is customers grouped under region. You can maintain this region as one of the attribute of customer and you can display this attribute in the report. Indirectly, this will give similar output to that of hierarchy.
    But lot depends on how your hierarchy is formed, before commenting whether it can be moved to master data attributes.
    Thanks.

  • BW-Query with hierarchy variable and webi-prompt

    Hi,
    I think I've got a quite simple question.
    I've got a SAP-BW-Query and a hierarchy variable, and some none hierarchy variables.
    All Variables work in the webi-prompt.
    For the none hierarchy variables I've got the chance to search for values in the LOV, but I can't search for
    values in the hierarchies.Can I enable this function to search?
    Kind regards
    Lars

    Hi
    I post the error once again. I made an easier query and i saw that last time the forum did some strange things.
    A database error occured. The database error text is: Die MDX-Abfrage
    SELECT { [Measures].[DC59N8GR349ETCCV3ZHIFFWGC] } ON COLUMNS
    FROM [ZTESTM01/Z_ZTESTM01_TEST5_VARIABLE]
    SAP VARIABLES [!V000002] INCLUDING [0FISCPER].[V62009001]
    konnte nicht ausgeführt werden. Fehler Specify a value for variable
    MMEP_FISCPER. (WIS 10901)
    The query runs perfect in RSRT.
    When i put the statement
    SELECT
    { [Measures].[DC59N8GR349ETCCV3ZHIFFWGC] } ON COLUMNS
    FROM [ZTESTM01/Z_ZTESTM01_TEST5_VARIABLE]
    SAP VARIABLES [!V000002] INCLUDING [0FISCPER].[V62009001]
    in MDXTEST, it gives a result.
    Best regards,
    Florian

  • Query to combine document series name and number

    Hi all,
    Example of Sales Quotation document numbering as following:
    Document series name: SQ10
    Document number: 1001
    Can I have a query to combine the series name and number as one field, e.g. SQ101001?
    This is for the purpose of if there is revision in a sales quotation, new quotation will be raise and UDF need to display previous sales quotation no.
    Thanks in advance!
    Phoebe

    Hi,
    Thanks for your help.
    Got the query as following:
    select T1.SeriesName + cast(T0.docnum as CHAR(15)) AS 'SQ No.', T1.[SeriesName],T0.[DocNum], T1.BeginStr AS 'Prefix', T0.[CardCode], T0.[CardName]
    from OQUT T0, NNM1 T1
    where T1.ObjectCode = 23 and T1.Series = T0.Series

  • Query with user-exit hierarchy variable and input ready hierarchy node var.

    Hello everyone.
    we are using several hierarchies (2005, 2006 and 2007) of the same info object 0FUNDS_CTR (one for each fiscal year). We would like to be able to use same reports regardless of chosen fiscal year (selected hierarchy) and ever more, to select node inside proper hierarchy. At the moment reports use 3 parameters:
    1) fiscal period from - fiscal period to
    2) hierarchy name
    3) hierarchy node
    Our goal is to get report with only 2 parameters:
    1) fiscal period from - fiscal period to
    2) hierarchy node
    since hierarchy name could be derived (user exit) from fiscal period.
    When user selects hierarchy node he is being asked to select hierarchy name (despite of user exit for hierarchy name) and key date (populated with current date).
    We would like to avoid step of user selecting hierarchy. Is it possible?
    Any other approaches to problem would be appreciated.
    Kind regards,
    Josko.

    Hi Jörg,
    As mentioned, I_STEP = 3 is  processed once per query, not once per varaiable.
    If this statement is placed within case-endcase for I_VNAM it never will be processed.
    Please take a look on this, it might be helpful..
    Regards
    Joe

  • How to find lasts query and his results(number of record returned)

    Hi all,
    sorry for my english.
    My scenario: i have 3 select below....
    first select: select 1 from dual;
    second select select 1 from dualXXXX; (this table/view/synonym, etc,etc NOT exists in DB)
    third select select 1 from dual where 0=1;
    my question is:
    how and where i can find (in system table for example) the latest query and the right or wrong excecution?
    I.E. for the first query the results is OK (with 1 record returned)
    for the second query the results is KO (the table not exists)
    for third query the results is OK( but whit 0 record returned).
    There is this information stored somewhere?
    Thanks a lot
    Attilio

    Properly executed queries details will be found in below dynamic views :
    V$SQL,V$SQLAREA
    SELECT
         sql_text,
         ROWS_PROCESSED,
         LAST_ACTIVE_TIME
    FROM
         V$SQLAREA
    WHERE
         regexp_like(SQL_TEXT,'1 from dual');Not aware about the queries which did not get executed properly.

  • What is the diff b/w logical query and physical query?

    Thanks In advance

    In OBIEE terms the logical query is how you query the BI Server, the Presentation services sends logical SQL to the BI Server, you can also write your own using JDBC , pull from BI Server using ODI etc.
    The BI Server engine takes this logical query and writes (a number of) phyiscal querie(s) to satisfy the logical request, depeninding on how your BMM and Physical layer is setup. There are a number of rules the BI Server evaluates before deciding the most appropriate Physical query to generate, rules include Physical Joins, Aggregate tales / Hierarchy levels and so on.
    Hope this helps,
    Good luck with interview :-)
    Alastair

  • Hierarchial Query 3 Levels

    Hello All,
    I have searched OTN and AskTom and saw many articles on hierarchial query but I just cannot seem to figure out how to apply it to my situation. Based on what I have read I do not believe CUBE or ROLLUP is the answer for this (maybe wrong..).
    This data is only a small part of a much larger query used for auditing purposes, so i would need to incorporate the solution for this into the larger query.
    Part of my problem is how to actual present this data in a format that would make sense to the end user, when included in a tabular (Excel) report.
    I am trying to devise a way to verify that monthly payment is received for each product. In this case, some of the products are "created" under another product and then billed under a 3rd product.
    To explain the table
    Prod_1 - list all products
    Prod_2 - lists only those products that are the parent of an item in the Prod_1 column.
    Prod_3 - shows there is a relationship between an item in Prod_1 that is not in Prod_2.
    There may be items in Prod_1 that have no relationship to Prod_2 or Prod_3 are those are just billed or *not getting billed BAD*
    There are other cases where there is a item in Prod_2 that is the parent of one or more items in Prod_1 but not related to Prod_3 and those are billed.
    There are other cases where there is a item in Prod_2 that is the parent of one or more items in Prod_1 but not related to Prod_3 and *not getting billed BAD*
    For example:
    +1-abcd-efgh, 3-qrst-uvwx and 5-ghij-klmn+ under Prod_1 is created under Prod_2 +1234-2f-maker-taker+ but billed under Prod_3 +87-test-789101+ at $139.11 MONTH_CHARGE.
    CREATE TABLE PRODT ( design_id VARCHAR2(50), Prod_1 VARCHAR2(50), Prod_2 VARCHAR2(50), Prod_3 VARCHAR2(50), Month_Charge NUMBER );
    INSERT INTO PRODT VALUES ( '8568','1-abcd-efgh', '1234-2f-maker-taker','', 0 );
    INSERT INTO PRODT VALUES ( '8569','2-ijkl-mnop', '5678-3f-maker-taker','', 0 );
    INSERT INTO PRODT VALUES ( '8570','3-qrst-uvwx', '1234-2f-maker-taker','', 0 );
    INSERT INTO PRODT VALUES ( '8571','4-yzab-cdef', '5678-3f-maker-taker','', 0 );
    INSERT INTO PRODT VALUES ( '8572','5-ghij-klmn', '1234-2f-maker-taker','', 0 );
    INSERT INTO PRODT VALUES ( '9421','1234-2f-maker-taker','','87-test-789101', 0 );
    INSERT INTO PRODT VALUES ( '9588','5678-3f-maker-taker','','88-test-123456', 0 );
    INSERT INTO PRODT VALUES ( '2531','87-test-789101', '', '1234-2f-maker-taker',139.11 );
    INSERT INTO PRODT VALUES ( '2532','88-test-123456', '','5678-3f-maker-taker', 159.45 );
    INSERT INTO PRODT VALUES ( '4531','76-test-101568', '', '',145.00 );
    INSERT INTO PRODT VALUES ( '3528','6-abcd-efgh', '2234-1f-maker-taker','', 0 );
    INSERT INTO PRODT VALUES ( '3529','7-ijkl-mnop', '2234-1f-maker-taker','', 0 );
    INSERT INTO PRODT VALUES ( '6261','2234-1f-maker-taker','','', 0 );
    COMMIT; Desired Result:
    Honestly - I am not sure of the best way to present it - definetly open for suggestions!
    The table shows there is a relationship by Product Number, but the table does not make it clear that as in the example above that
    all of the underlying products are being billed under +87-test-789101+ at $139.11 per month.
    I must still show all of the Prod columns - so for my understanding Cube or Rollup is not a good fit(?).
    That is what I am trying to accomplish - in other words I am getting paid for everything or not?
    In my mind I see it something like this perhaps:
    DESIGN_ID             PROD_1                    PROD_2                       PROD_3                    MONTH_CHARGE                BILL_INDICATOR
    8569                    2-ijkl-mnop                 5678-3f-maker-taker         NULL                                 0                         ? (Not sure how to indicate
    8571                    4-yzab-cdef                5678-3f-maker-taker         NULL                                 0                         what should be displayed
    9588                    5678-3f-maker-taker    NULL                           88-test-123456                     0                         in this new column to make
    2532                    88-test-123456          NULL                            5678-3f-maker-taker           159.45                    the Audit process simple *Help Needed*)Thanks for looking!
    G
    Edited by: GMoney on Aug 22, 2012 12:54 PM
    Edited by: GMoney on Aug 22, 2012 12:57 PM

    Frank,
    I was hoping you would cross paths with this post.
    I am building on a TOP N query you helped me with in another post.
    As I mentioned in my an initial post, I have products that may be in a hierarchical order (or stand alone) could be billed as primary or with secondary or tertiary products that are billed under the primary. Meaning the primary would have a dollar figure associated, and may or may not have secondary or tertiary products related to it.
    To explain the table
    Prod_1 - list all products
    Prod_2 - lists only those products that are the parent of an item in the Prod_1 column.
    Prod_3 - shows there is a relationship between an item in Prod_1 that is not in Prod_2.
    There may be items in Prod_1 that have no relationship to Prod_2 or Prod_3 are those are just billed or not getting billed BAD
    There are other cases where there is a item in Prod_2 that is the parent of one or more items in Prod_1 but not related to Prod_3 and those are billed.
    There are other cases where there is a item in Prod_2 that is the parent of one or more items in Prod_1 but not related to Prod_3 and not getting billed BAD
    My business requirement is to present all of the results from the initial query as well as adding in the dollar figures from an addition query against another financial table. I need to be able to make it perfectly clear to an end user auditor that each and every product is being billed, and clearly identify the secondary or tertiary items if there are any that fall under that primary product.
    My real hung up here is the presentation of the data. I can easily see the correlation between them but it is not likely an end user would.
    DESIGN_ID             PROD_1                    PROD_2                       PROD_3                 MONTH_CHARGE       BILL_INDICATOR
    8569                    2-ijkl-mnop                 5678-3f-maker-taker         NULL                             0              ? (Not sure how to indicate
    8571                    4-yzab-cdef                5678-3f-maker-taker         NULL                             0                 what should be displayed
    9588                    5678-3f-maker-taker    NULL                           88-test-123456                 0                 in this new column to make
    2532                    88-test-123456          NULL                            5678-3f-maker-taker      159.45 ;          the Audit process simple *Help Needed*) Thanks for looking,
    Greg

  • Hierarchy Query

    Hi All..
    I have a hierarchy query with description as below
    SQL> desc manager_entity;
    Name                                      Null?    Type
    MANAGER_ENTITY_ID               NOT NULL NUMBER
    MANAGER_ENTITY_TYPE_ID      NOT NULL NUMBER
    MANAGER_ENTITY_PARENT_ID                  NUMBER
    CREATE_USER                          NOT NULL  VARCHAR2(50)
    CREATE_DATETIME                    NOT NULL DATE
    LAST_UPDATE_USER                 NOT NULL  VARCHAR2(50)
    LAST_UPDATE_DATETIME           NOT NULL DATE
    MANAGER_ENTITY_LINK_ID       NOT NULL  NUMBERI got the correct relation between the parent and child using the below query
    select  me.manager_entity_id
    ,      me.manager_entity_type_id
    ,      me.manager_entity_parent_id
    ,      me.manager_entity_link_id
    ,      level
    from manager_entity me
    start with me.manager_entity_id=:p_id
    connect by prior me.manager_entity_id=me.manager_entity_parent_idWhen I try to join this table with other 3 tables I’m unable to retrieve data. Description of the other 3 tables
    SQL> desc manager_product;
    Name                                      Null?    Type
    MANAGER_PRODUCT_ID                        NOT NULL NUMBER
    MANAGER_PRODUCT_NAME                      NOT NULL VARCHAR2(50)
    MANAGER_ROOF_ID                           NOT NULL NUMBER
    ACT_STRATEGY                                       VARCHAR2(50)
    ACT_SUB_STRATEGY                                   VARCHAR2(50)
    ACT_DATE_ENTERED                                   DATE
    ACT_INCEPTION_DATE                                 DATE
    ACT_PEER_GROUP                                     VARCHAR2(50)
    BACK_OFFICE_RISK_ID                                NUMBER
    AREA_ID                                            NUMBER
    ACT_CREATE_DATE                                    DATE
    PROCESS_STOP_DATE                                  DATE
    TARGET_COMPLETION_DATE                             DATE
    REVISIT_DATE                                       DATE
    CREATE_USER                                        VARCHAR2(50)
    CREATE_DATETIME                                    DATE
    LAST_UPDATE_USER                                   VARCHAR2(50)
    LAST_UPDATE_DATETIME                               DATE
    SQL> desc manager_roof;
    Name                                      Null?    Type
    MANAGER_ROOF_ID                           NOT NULL NUMBER
    MANAGER_ROOF_NAME                         NOT NULL VARCHAR2(50)
    ROOF_COMPANY_ID                           NOT NULL NUMBER
    CREATE_USER                                        VARCHAR2(50)
    CREATE_DATETIME                                    DATE
    LAST_UPDATE_USER                                   VARCHAR2(50)
    LAST_UPDATE_DATETIME                               DATE
    SQL> desc investment_vehicle;
    Name                                      Null?    Type
    INVESTMENT_VEHICLE_ID                     NOT NULL NUMBER
    INVESTMENT_VEHICLE_NAME                   NOT NULL VARCHAR2(255)
    INVESTMENT_VEHICLE_ARRT_NAME                       VARCHAR2(255)
    INVESTIER_SYSID                                    NUMBER
    INVESTIER_ID                                       VARCHAR2(100)
    MANAGER_PRODUCT_ID                                 NUMBER
    TRADING_STRUCTURE_TYPE_ID                          NUMBER
    LEGAL_DESIGNATION_ID                               NUMBER
    ADDITIONAL_INVEST_FORM_TYPE_ID                     NUMBER
    INVESTMENT_VEH_CLASS_TYPE_ID                       NUMBER
    ERISA_PLAN_ASSET_CATEGORY_ID                       NUMBER
    SIDE_LETTER_FLAG                                   CHAR(1)
    INCEPTION_DATE                                     DATE
    ALLOW_ERISA_FLAG                                   CHAR(1)
    ALLOW_PLAN_ASSET_FLAG                              CHAR(1)
    ALLOW_US_TAXABLE_INVESTOR_FLAG                     CHAR(1)
    ALLOW_OFFSHORE_INVESTOR_FLAG                       CHAR(1)
    SUB_DOC_DEADLINE                                   NUMBER
    WIRE_DEADLINE                                      NUMBER
    DOMICILE_COUNTRY_ID                                NUMBER
    CREATE_USER                                        VARCHAR2(50)
    CREATE_DATETIME                                    DATE
    LAST_UPDATE_USER                                   VARCHAR2(50)
    LAST_UPDATE_DATETIME                               DATE
    PERTRAC_DATA_VENDOR_ID                             VARCHAR2(255)
    PERTRAC_DATA_VENDOR_NAME                           VARCHAR2(255)
    FTS_NAME                                           VARCHAR2(255)
    MATLAB_MANAGER_NAME                                VARCHAR2(255)
    ACT_CO_FUND_NAME                                   VARCHAR2(255)
    ACT_INVESTMENT_VEHICLE_NAME                        VARCHAR2(255)
    SIDE_POCKET_PCT                                    NUMBER
    MAX_ILLIQUID_PCT                                   NUMBER
    CONTRIBUTION_OPENING_ID                            NUMBER
    MANAGEMENT_FEE_PCT                                 NUMBER
    INCENTIVE_FEE_PCT                                  NUMBER
    SIDE_POCKET_NOTE                                   VARCHAR2(4000)
    FTS_ID                                             NUMBERI was trying to join the other 3 tables with the main query as below..
    select  me.manager_entity_id
    ,      me.manager_entity_type_id
    ,      me.manager_entity_parent_id
    ,      me.manager_entity_link_id
    ,      level
    from manager_entity me
    ,    manager_roof mr
    ,    manager_product mp
    ,    investment_vehicle iv
    where me.manager_entity_link_id= mr.manager_roof_id
    and   mr.manager_roof_id= mp.manager_roof_id
    and   mp.manager_product_id= iv.manager_product_id
    start with me.manager_entity_id=:p_id
    connect by prior me.manager_entity_id=me.manager_entity_parent_idHere manager_entity_link_id of manager_entity table represents(or has) the primary key of all the other 3 table..like
    Enter value for p_id: 1
    old   7: start with me.manager_entity_id=&p_id
    new   7: start with me.manager_entity_id=1
    MANAGER_ENTITY_ID MANAGER_ENTITY_TYPE_ID MANAGER_ENTITY_PARENT_ID
    MANAGER_ENTITY_LINK_ID      LEVEL
                    1                   1008
                     14793          1
                  263                   1009                        1
                     19695          2
                  803                   1010                      263
                   7031783          3
    MANAGER_ENTITY_ID MANAGER_ENTITY_TYPE_ID MANAGER_ENTITY_PARENT_ID
    MANAGER_ENTITY_LINK_ID      LEVEL
                  804                   1010                      263
                   7031782          3
                  805                   1010                      263
                   7031781          3The above is the output for the hierarchy query
    Here the MANAGER_ENTITY_LINK_ID has values (14793, 19695, 7031783 , 7031782 , 7031781)
    Where 14793 is the manager_roof_id in manager_roof_table
    19695 is the manager_product_id in the manager_product table
    7031783 , 7031782 , 7031781 are the investment_vehicle_id’s in the investment_vehicle table…
    In the output I need to retrieve manager_roof_name, manager_product_name, investment_vehicle_name..
    Thanks in advance
    HTH
    Edited by: user10280715 on Dec 3, 2008 11:55 AM

    The reason result show as no rows selected is your first insert. If fails since column list has 3 columns while values list has 4 values. You probably missed "ORA-00913: too many values" error:
    SQL> drop table manager_entity
      2  /
    Table dropped.
    SQL> create table manager_entity(manager_entity_id number,manager_entity_type_id number,manager_entity_parent_id number,manager_entity_link_id number)
      2  /
    Table created.
    SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_link_id)
      2  values(1,1008,null,14793)
      3  /
    insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_link_id)
    ERROR at line 1:
    ORA-00913: too many values
    SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
      2  values(263, 1009, 1, 19695)
      3  /
    1 row created.
    SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
      2  values(803, 1010, 263, 7031783)
      3  /
    1 row created.
    SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
      2  values(804, 1010, 263, 7031782)
      3  /
    1 row created.
    SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
      2  values(805, 1010, 263, 7031781)
      3  /
    1 row created.
    SQL> drop table manager_roof
      2  /
    Table dropped.
    SQL> create table manager_roof(manager_roof_id number,manager_roof_name varchar2(20))
      2  /
    Table created.
    SQL> insert into manager_roof(manager_roof_id,manager_roof_name)
      2  values(14793,'roof')
      3  /
    1 row created.
    SQL> drop table manager_product
      2  /
    Table dropped.
    SQL> create table manager_product(manager_product_id number,manager_product_name varchar2(20),manager_roof_id number)
      2  /
    Table created.
    SQL> Insert into manager_product(manager_product_id,manager_product_name,manager_roof_id)
      2  Values(19695,'product1', 14793)
      3  /
    1 row created.
    SQL> drop table investment_vehicle
      2  /
    Table dropped.
    SQL> create table investment_vehicle(investment_vehicle_id number,manager_product_id number,investment_vehicle_name  varchar2(20))
      2  /
    Table created.
    SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
      2  Values(7031781,19695,'inv1')
      3  /
    1 row created.
    SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
      2  Values(7031782,19695,'inv3')
      3  /
    1 row created.
    SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
      2  Values(7031783,19695,'inv3')
      3  /
    1 row created.
    SQL> COMMIT
      2  /
    Commit complete.
    SQL>
    SQL> select  me.manager_entity_id
      2  ,      me.manager_entity_type_id
      3  ,      me.manager_entity_parent_id
      4  ,      me.manager_entity_link_id
      5  ,      level
      6  from manager_entity me
      7  start with me.manager_entity_id=&p_id
      8  connect by prior me.manager_entity_id=me.manager_entity_parent_id
      9 
    SQL> /
    Enter value for p_id: 1
    old   7: start with me.manager_entity_id=&p_id
    new   7: start with me.manager_entity_id=1
    no rows selectedAs soon as you fix the error:
    SQL> drop table manager_entity
      2  /
    Table dropped.
    SQL> create table manager_entity(manager_entity_id number,manager_entity_type_id number,manager_entity_parent_id number,manager_entity_link_id number)
      2  /
    Table created.
    SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
      2  values(1,1008,null,14793)
      3  /
    1 row created.
    SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
      2  values(263, 1009, 1, 19695)
      3  /
    1 row created.
    SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
      2  values(803, 1010, 263, 7031783)
      3  /
    1 row created.
    SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
      2  values(804, 1010, 263, 7031782)
      3  /
    1 row created.
    SQL> insert into manager_entity(manager_entity_id,manager_entity_type_id,manager_entity_parent_id,manager_entity_link_id)
      2  values(805, 1010, 263, 7031781)
      3  /
    1 row created.
    SQL> drop table manager_roof
      2  /
    Table dropped.
    SQL> create table manager_roof(manager_roof_id number,manager_roof_name varchar2(20))
      2  /
    Table created.
    SQL> insert into manager_roof(manager_roof_id,manager_roof_name)
      2  values(14793,'roof')
      3  /
    1 row created.
    SQL> drop table manager_product
      2  /
    Table dropped.
    SQL> create table manager_product(manager_product_id number,manager_product_name varchar2(20),manager_roof_id number)
      2  /
    Table created.
    SQL> Insert into manager_product(manager_product_id,manager_product_name,manager_roof_id)
      2  Values(19695,'product1', 14793)
      3  /
    1 row created.
    SQL> drop table investment_vehicle
      2  /
    Table dropped.
    SQL> create table investment_vehicle(investment_vehicle_id number,manager_product_id number,investment_vehicle_name  varchar2(20))
      2  /
    Table created.
    SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
      2  Values(7031781,19695,'inv1')
      3  /
    1 row created.
    SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
      2  Values(7031782,19695,'inv3')
      3  /
    1 row created.
    SQL> Insert into investment_vehicle(investment_vehicle_id,manager_product_id,investment_vehicle_name)
      2  Values(7031783,19695,'inv3')
      3  /
    1 row created.
    SQL> COMMIT
      2  /
    Commit complete.
    SQL>
    SQL> select  me.manager_entity_id
      2  ,      me.manager_entity_type_id
      3  ,      me.manager_entity_parent_id
      4  ,      me.manager_entity_link_id
      5  ,      level
      6  from manager_entity me
      7  start with me.manager_entity_id=&p_id
      8  connect by prior me.manager_entity_id=me.manager_entity_parent_id
      9 
    SQL> /
    Enter value for p_id: 1
    old   7: start with me.manager_entity_id=&p_id
    new   7: start with me.manager_entity_id=1
    MANAGER_ENTITY_ID MANAGER_ENTITY_TYPE_ID MANAGER_ENTITY_PARENT_ID MANAGER_ENTITY_LINK_ID      LEVEL
                    1                   1008                                           14793          1
                  263                   1009                        1                  19695          2
                  803                   1010                      263                7031783          3
                  804                   1010                      263                7031782          3
                  805                   1010                      263                7031781          3
    SQL> SY.

  • 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

  • Web Analysis Error -- Error while executing query and retrieving data

    Regarding Web Analysis:
    We have a number of reports that we created. yesterday they were all working fine. today we try to open them and most are generating an error.
    The error is:
    Error while executing query and retrieving data.; nested exception is:
    com.hyperion.ap.APException: [1033] Native:
    1013033[Thu Oct 22 09:08:17
    2009]server name/application name/database name/user name/Error91013033)
    ReportWriter exit abnormally
    Does anyone have any insight into what is going on?
    My version information is:
    Hyperion System 9 BI+ Analytic Administration Services 9.3.0.1.1 Build 2
    Web Analysis 9.3.0.0.0.286
    Thanks in advance for your help.
    DaveW

    Hi,
    And also click on check option by opening the query in Query designer,as Mr . Arun suggested.
    And if you get any error in checking, see the long message(detail).
    With rgds,
    Anil Kumar Sharma .P

  • SQL Query - The number of columns specified in "SQL Query" does not match t

    I am creating new UDM for tablespace alert, below is my query,however its failing with error
    SQL Query - The number of columns specified in "SQL Query" does not match the value specified in "SQL Query Output"
    I selected Metric type is number
    SQL Query Format : Two columns
    Query:
    SELECT d.tablespace_name,round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2)
    used_pct FROM sys.dba_tablespaces d,(select tablespace_name, sum(bytes) bytes, sum(greatest(maxbytes,bytes)) maxbytes from sys.dba_data_files group by tablespace_name) a,(select tablespace_name, sum(bytes) bytes from sys.dba_free_space group by tablespace_name) f
    WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+)
    AND NOT (d.extent_management = 'LOCAL' AND d.contents = 'TEMPORARY');
    Any clues why i am getting error.

    SQL> SELECT d.tablespace_name,round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2) used_pct
    2 FROM sys.dba_tablespaces d,(select tablespace_name, sum(bytes) bytes, sum(greatest(maxbytes,bytes)) maxbytes from sys.dba_data_files group by tablespace_name) a,(select tablespace_name, sum(bytes) bytes from sys.dba_free_space group by tablespace_name) f
    3 WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+)
    4 AND NOT (d.extent_management = 'LOCAL' AND d.contents = 'TEMPORARY');
    TABLESPACE_NAME USED_PCT
    MGMT_TABLESPACE .82
    SYSAUX 1.52
    UNDOTBS1 .32
    RMAN .02
    CORRUPT_TS 10.63
    USERS 0
    SYSTEM 2.26
    MGMT_ECM_DEPOT_TS .04
    MGMT_AD4J_TS 0

  • ORDER BY IN HIERARCHIAL QUERY

    Cosider the following record set from the emp table.
    empno ename mgr
    7839 KING     
    7566 SCOTT 7839
    7566 BLAKE 7839
    7782 CLARK 7839
    If I use the following hierarchial query to populate a tree in Oracle forms
    I will get the result as shown below.
    Query
    =====
    select -1, level, ename, null, ename
    from emp
    where empno in (7839,7566,7698,7782)
    start with ename = 'KING'
    connect by mgr = prior empno;
    Result
    ======
    KING
    JONES
    BLAKE
    CLARK
    Here is my problem. Though diffrent employees can work under a manager,
    we have some internal rules that assigns an order to each employee who
    works under a manager. This helps us in identifying who should take
    charge in the absence of a manager.
    I have added one column to the emp table, in order to store the order in
    which the employee reports to the manager.
    Now the record set becomes
    empno ename mgr emp_order
    7839 KING     0
    7566 SCOTT 7839 1
    7566 BLAKE 7839 3
    7782 CLARK 7839 2
    Now I want the forms tree to be displayed as shown below.
    KING
    JONES
    CLARK
    BLAKE
    (In short, I want the records in a particular level to be displayed
    according to a pre-defined order, rather than getting them displayed
    randomly).
    Which query can I use for this purpose ?
    Please help....
    Shibu

    Hi Guys,
    Thanks a lot for your suggestions.
    It really works great in SQL Plus.
    I am familiar with Oracle Forms and I know how to use it if I want to build a tree in Forms.
    Here is my requirement. I want to build the application using Oracle Portal. I know that there is something called 'Hierarchy' available in Portal. I don't know up to what extend it gives flexibility in programatically populating the tree.
    Here is the scenario. I will use the hierarchial query with CONNECT SIBLINGS BY clause to populate the a tree which will show me employees in a department hierarchially.
    Eg:
    KING
    SCOTT
    BLAKE
    SMITH
    Now I like to show the projects assigned to each employee, which itself can be considered as another hierarchy.
    Eg of Projects hierarchy.
    Projects
    Development
    Oracle Applications
    HRMS
    Support
    Intranet Applications
    Suppose SCOTT is working in HRMS project, the tree should show as,
    KING
    SCOTT
    Projects
    Development
    Oracle Applications
    HRMS
    BLAKE
    SMITH
    I can color code the node which will distinguish between an employee and his assignments.
    Is there a way to achieve it in Oracle Portal using the 'Hierarchy' or what may be the best way to go (Applet etc...) ???
    Thanks in advance for your help.
    Shibu

  • Hierarchy  Query  to  get  parent  nodes?

    Hi Everyone,
    I want to write a hierarchy query which should give me the path starting from given node to its parents(Grand parents). 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(5),CHILD VARCHAR2(5) 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 'F' which gives the path from bottom to up.
    A<-B<-D<-F
    My Query:
    SELECT substr(sys_connect_by_path(child,'<-'),3)
    FROM relation
    WHERE connect_by_isleaf = 1
    START WITH child = 'F'
    CONNECT BY PRIOR parent = child
    ORDER BY child;
    Output of my query:
    F<-D<-B<-A
    I am getting the output in reverse order. i can use the reverse string function to reverse the string but the problem is the node can also contain the values like 'AC' 'BA'.. in future.
    Can anyone please help me in getting the correct output.
    Thank you in advance.

    I like ListAgg :D
    with RELATION(PARENT,CHILD) as(
    select NULL,'A' from dual union all
    select 'A', 'B' from dual union all
    select 'A', 'C' from dual union all
    select 'B', 'D' from dual union all
    select 'B', 'E' from dual union all
    select 'D', 'F' from dual union all
    select 'C', 'G' from dual union all
    select NULL,'H' from dual union all
    select 'H', 'I' from dual union all
    select 'H', 'J' from dual)
    SELECT ListAgg(child,'<-')
           within group(order by Level desc) as revPath
    FROM relation
    START WITH child = 'F'
    CONNECT BY PRIOR parent = child;
    revPath
    A<-B<-D<-F

Maybe you are looking for

  • Is it possible to sort my library by both "Rating" AND "Last Played?"

    I have been transferring my music digitally since 5 years before iTunes ever existed. I have just finally developed a rating system that I will be able to benefit from.  So, I want go though almost two decades worth of my music, and rate all these so

  • Time Capsule external HD slow after joining an existing network.

    Hi all, I have recently moved and had to reconfigure my TC accordingly. Previously my TC was connected to the internet and an external HD which hosted my iTunes music (amongst other files). After moving home, I was required to join the existing wifi

  • UD without batch

    Dear all, I have met some problem about QM and PP interface, please help me take a look. I created a process order for material, which has the been set Batch management, and then after release order, the inspection lot created which need to be batch

  • Travel Expense Category

    Hi, Is there a way to add travel expense category? I tried searching for all the config nodes within Travel Management, but I couldn't find it. Thanks.

  • Why does terminal behave differently with respect to "Resume" feature?

    Terminal behaves a little funky when it comes to the new "Resume" feature in Lion.  Here's a few interesting notes: When restarting, Terminal prompts the user to close itself.  If you don't click close in time, the reboot process is halted.  This ***