Hierarchical difficult query.

Hi guys,
I am trying to solve this issue in one select and still I did not manage to find the sollution.
I have a table with the following configuration:
DROP TABLE USERS_TAB;
create table users_tab (user_id number PRIMARY KEY, group_id number, USERTYPE VARCHAR2 (2));
--THESE USERS ARE IN THE SAME GROUP id:80 and have different types
INSERT INTO users_tab VALUES (1,80,'V');
INSERT INTO users_tab VALUES (2,80,'V');
INSERT INTO users_tab VALUES (3,80,'E');
--These are in another group (40) and have different types
INSERT INTO users_tab VALUES (4,40,'E');
INSERT INTO users_tab VALUES (5,40,'V');
INSERT INTO users_tab VALUES (6,40,'E');
insert into users_tab values (7,null, 'V');
commit;
create table links (v_type_users number, e_type_users number);In links table we define the links between users. A link appears only one time in this table (the links are one to one). the v type users appear in v_type_user column and e type users appear in e_type_user
**I have a procedure that has for input parameter one user_id. I need to selectal users that have the same group_id with the input and that are lnked togheter. if a contract belongs to a group, all memenbers of the group need to be included and the links between groups are made in links table (you will understand from example). **
For example:
1.
truncate table links;
insert into links values (1,4);user 1 of v type is linked with user 4 of e type.
if my select has for input user the id 1,
it will need to return all the users that are in the group of user 1. and for these users all the links with their
groups and so on.
1 is in group 80...so I will need to return 1,2,3 users. but 1 is linked with 4 that is in group 40 so I will also return 4,5,6 because they are in the same group
so in this link I will need to return 1,2,3,4,5,6. they are representing a bigger group
2.
truncate table links;
insert into links values (1,4);
insert into links values (5,7);--we created a link between 5(type v and 7 type e)if we input user 1, we will need to show all memember from group 80, and because of the link (1,4) we will need to show
4 and because 4 is in the group with 5 and 6 we will need to show them also and because 5 is in link with 7 we will need to show 7 also
the group will be: 1,2,3,4,5,6,7.
**you can see that the bigger group will be the same no matter what the input is. if the input is for example 7 or 5 or (4,3,2,1) we will output*
*1,2,3,4,5,6,7. because 7 is in link with 5 and 5 is in a group and in that group there is another link to another group**
3.
We can have multimple links between groups (I can see here a problem with hierarchical or maybe nocycle and distinct helps?)
truncate table links;
insert into links values (1,4);
insert into links values (5,7);--we created a link between 5(type v) and 7 type e
insert into links values (2,6);--we created a link between 2(type v) and 6 type ethis will not change the output, although we have multimple links.
we will need to output:
1
2
3
4
5
6
7
4.
truncate table links;
insert into links values (3,7);-- we have one link between 3(type v) and 7 (type e)if we have the input user 3. we will need to show all memenber from the group of user 3 and because of the link we will show the user 7.
we will have
1
2
3
7
5.
truncate table links;
if we have no link...we will need to show all the users from a group(if the input is a user from a group) and only that user if the input has no group.
I think this is a difficult one, any help is appreaciated.
Thanks

Hi,
Interesting problem!
The CONNECT BY should really be done by groups; it doesn't matter that userid 1 is linked to userid 4; all that matters is that group 80 is linked to group 40.
But if the CONNECT BY is done accrding to groups, what about user_id=7, who is not in a group? For purposes of this query, all rows in users_tab that have NULL group_id will be assigned a unique group_id.
Sub-query erverybody_in_group below makes up a group_id for rows that do not already have one. It assumes that userid > 0.
The CONNECT BY will go a lot easier if, for every row like (1, 4) that is in links, we also have the mirror-image (4, 1). The first two branches of the UNION in sub-query group_link do that.
The last branch of the UNION makes sure all groups are represented in group_link, even if they are not linked to anything. That ensures that all members of the source group get included in hte results, even if they are not connected to any other group. (This incluudes the special case where there are no rows at all in linkls.)
WITH     everybody_in_group     AS
     SELECT     user_id
     ,     COALESCE ( group_id
                , user_id + ( SELECT  MAX (group_id)
                              FROM    users_tab
                ) AS group_id
     FROM    users_tab
,     group_link          AS
     SELECT     v1.group_id     AS from_group_id
     ,     e1.group_id     AS to_group_id
     FROM     links               l1
     JOIN     everybody_in_group     e1     ON     l1.e_type_users     = e1.user_id
     JOIN     everybody_in_group     v1     ON     l1.v_type_users     = v1.user_id
     UNION
     SELECT     e2.group_id     AS from_group_id
     ,     v2.group_id     AS to_group_id
     FROM     links               l2
     JOIN     everybody_in_group     e2     ON     l2.e_type_users     = e2.user_id
     JOIN     everybody_in_group     v2     ON     l2.v_type_users     = v2.user_id
     UNION
     SELECT  group_id     AS from_group_id
     ,     NULL          AS to_group_id
     FROM     everybody_in_group
SELECT     user_id
FROM     everybody_in_group
WHERE     group_id     IN ( SELECT  from_group_id
                    FROM    group_link
                    START WITH      from_group_id = ( SELECT  group_id
                                                      FROM        everybody_in_group
                                      WHERE   user_id     = 1     -- Or use a bind variable
                    CONNECT BY NOCYCLE      from_group_id = PRIOR to_group_id
ORDER BY  user_id
;In the example above, the starting user_id (1) is hard-coded, about 6 lines from the end. This is the only place where that parameter is used.
The column usertype plays no role in this problem; is that right?
Thanks for posting the CREATE TABLE and INSERT statements! That really helps.

Similar Messages

  • Hierarchical + Analytical query for organizational unit parameters

    Hello gurus,
    I try for a couples of hour ago to make a query work as I would like.
    Our application need to store some parameters for our organization units. These organization units are typically organized in in an hierarchy manner: one top unit with many level of child units. The parameters are stored into another table with 1:1 relationship.
    For sake of visualisation, here is the data for the organization unit and parameter table in a more visual format:
    SQL> select * from organization_unit;
    UNIT_CODE  UNIT_NAME            PARENT_UNIT_CODE
    00000      Top level
    10         L2 unit #10          00000
    10-01      L3 unit #10-01       10
    10-02      L3 unit #10-02       10
    20         L2 unit #20          00000
    20-01      L3 unit #20-01       20
    20-02      L3 unit #20-02       20
    SQL>  select * from org_unit_parameters;
    UNIT_CODE  PARAM1               PARAM2               PARAM3               PARAM4
    00000      Default value        Default value        Default value        {null}
    10         {null}               Value from 10        Value from 10        {null}
    10-01      {null}               {null}               Value from 10-01     {null}
    10-02      {null}               {null}               {null}               Value from 10-02
    20         Value from 20        Value from 20        Value from 20        {null}
    20-01      {null}               Value from 20-01     {null}               {null}
    20-02      {null}               Value from 20-02     {null}               {null}The application will query the parameter table to get a parameter value for a given unit.
    The parameter resolution algorithm is rather simple: when querying a unit, the applicable parameter is the one defined at the requested level. If the parameter is not defined (null) at the requested level, the parameter value that must be returned is the next defined one in the parent hierarchy. In some rare cases, it can be null if a parameter is not defined anywhere from the requested level to top.
    I've made a query that seems to work when querying for one unit at a time. It use hierarchical operators (start with + connect by) with a bit of analytical functions. Here is a test & raw output example:
    SQL> WITH hierarchy
      2  AS
      3  (
      4    SELECT ou.unit_code,
      5         LEVEL            AS lvl
      6    FROM   organization_unit ou
      7    START WITH
      8      ou.unit_code = '20-01'
      9    CONNECT BY
    10      ou.unit_code = PRIOR ou.parent_unit_code
    11  )
    12  SELECT h.*,
    13       p.param1                                                        AS param1_raw,
    14       LAST_VALUE (p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param1_with_last,
    15       FIRST_VALUE(p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param1_with_first,
    16       p.param2                                                        AS param2_raw,
    17       LAST_VALUE (p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param2_with_last,
    18       FIRST_VALUE(p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param2_with_first,
    19       p.param3                                                        AS param3_raw,
    20       LAST_VALUE (p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param3_with_last,
    21       FIRST_VALUE(p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param3_with_first,
    22       p.param4                                                        AS param4_raw,
    23       LAST_VALUE (p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param4_with_last,
    24       FIRST_VALUE(p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param4_with_first
    25  FROM   hierarchy                                h
    26         LEFT JOIN org_unit_parameters         p
    27         ON h.unit_code = p.unit_code
    28  ORDER BY h.lvl DESC;
    UNIT_CODE   LVL PARAM1_RAW           PARAM1_WITH_LAST     PARAM1_WITH_FIRST    PARAM2_RAW           PARAM2_WITH_LAST     PARAM2_WITH_FIRST    PARAM3_RAW           PARAM3_WITH_LAST     PARAM3_WITH_FIRST    PARAM4_RAW           PARAM4_WITH_LAST     PARAM4_WITH_FIRST
    00000         3 Default value        Default value        Value from 20        Default value        Default value        Value from 20-01     Default value        Default value        Value from 20        {null}               {null}               {null}
    20            2 Value from 20        Value from 20        Value from 20        Value from 20        Value from 20        Value from 20-01     Value from 20        Value from 20        Value from 20        {null}               {null}               {null}
    20-01         1 {null}               Value from 20        {null}               Value from 20-01     Value from 20-01     Value from 20-01     {null}               Value from 20        {null}               {null}               {null}               {null}Seems pretty good, the upper parameters are well «propagated» down with LAST_VALUE function. But, I don't understand why the use of FIRST_VALUE and oppposite ordering doesn't give the same result. A little more playing with the last query for getting the final result for a given unit code:
    SQL> SELECT *
      2  FROM
      3  (
      4     WITH hierarchy
      5     AS
      6     (
      7        SELECT ou.unit_code,
      8               LEVEL            AS lvl
      9        FROM   organization_unit ou
    10        START WITH
    11           ou.unit_code = '20-01'
    12        CONNECT BY
    13           ou.unit_code = PRIOR ou.parent_unit_code
    14     )
    15     SELECT h.*,
    16            LAST_VALUE (p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param1,
    17            LAST_VALUE (p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param2,
    18            LAST_VALUE (p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param3,
    19            LAST_VALUE (p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param4
    20     FROM   hierarchy                                h
    21               LEFT JOIN org_unit_parameters         p
    22               ON h.unit_code = p.unit_code
    23     ORDER BY h.lvl
    24  )
    25  WHERE ROWNUM = 1;
    UNIT_CODE   LVL PARAM1               PARAM2               PARAM3               PARAM4
    20-01         1 Value from 20        Value from 20-01     Value from 20        {null}Works well!
    But, my ultimate goal is to create a view that resolve correctly all these parameters for each level of the organization with proper propagation rather then querying for each unit at a time. I played a bit, but without success. :( My current raw query is this one:
    SQL> WITH hierarchy
      2  AS
      3  (
      4     SELECT ou.unit_code,
      5            LPAD(' ',2*(LEVEL-1)) || ou.unit_code    AS tree,
      6            LEVEL                                    AS lvl
      7     FROM   organization_unit ou
      8     START WITH
      9        parent_unit_code IS NULL
    10     CONNECT BY
    11        PRIOR unit_code =  parent_unit_code
    12  )
    13  SELECT h.*,
    14         p.param1                                                        AS param1_raw,
    15         LAST_VALUE (p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param1_with_last,
    16         FIRST_VALUE(p.param1 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param1_with_first,
    17         p.param2                                                        AS param2_raw,
    18         LAST_VALUE (p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param2_with_last,
    19         FIRST_VALUE(p.param2 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param2_with_first,
    20         p.param3                                                        AS param3_raw,
    21         LAST_VALUE (p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param3_with_last,
    22         FIRST_VALUE(p.param3 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param3_with_first,
    23         p.param4                                                        AS param4_raw,
    24         LAST_VALUE (p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl DESC)   AS param4_with_last,
    25         FIRST_VALUE(p.param4 IGNORE NULLS) OVER (ORDER BY h.lvl ASC)    AS param4_with_first
    26  FROM   hierarchy                          h
    27            LEFT JOIN org_unit_parameters   p
    28            ON h.unit_code = p.unit_code
    29  ORDER BY h.unit_code;
    UNIT_CODE  TREE        LVL PARAM1_RAW                PARAM1_WITH_LAST          PARAM1_WITH_FIRST      PARAM2_RAW                   PARAM2_WITH_LAST          PARAM2_WITH_FIRST         PARAM3_RAW                PARAM3_WITH_LAST          PARAM3_WITH_FIRST         PARAM4_RAW                PARAM4_WITH_LAST       PARAM4_WITH_FIRST
    00000      00000         1 Default value             Default value             Default value          Default value                Default value             Default value             Default value             Default value             Default value             {null}                    Value from 10-02       {null}
    10           10          2 {null}                    Value from 20             Default value          Value from 10                Value from 10             Default value             Value from 10             Value from 10             Default value             {null}                    Value from 10-02       {null}
    10-01          10-01     3 {null}                    {null}                    Default value          {null}                       Value from 20-02          Default value             Value from 10-01          Value from 10-01          Default value             {null}                    Value from 10-02       Value from 10-02
    10-02          10-02     3 {null}                    {null}                    Default value          {null}                       Value from 20-02          Default value             {null}                    Value from 10-01          Default value             Value from 10-02          Value from 10-02       Value from 10-02
    20           20          2 Value from 20             Value from 20             Default value          Value from 20                Value from 10             Default value             Value from 20             Value from 10             Default value             {null}                    Value from 10-02       {null}
    20-01          20-01     3 {null}                    {null}                    Default value          Value from 20-01             Value from 20-02          Default value             {null}                    Value from 10-01          Default value             {null}                    Value from 10-02       Value from 10-02
    20-02          20-02     3 {null}                    {null}                    Default value          Value from 20-02             Value from 20-02          Default value             {null}                    Value from 10-01          Default value             {null}                    Value from 10-02       Value from 10-02As you can see, it's not as I expected. I know there's something to do with a PARTITION BY clause, but don't know how.
    Is anyone knows how to solve my problem?
    Thanks
    Bruno
    For reproductibility purposes, here is the code to create sturcture and data:
    Here is the format of my tables and some samble data:
    CREATE TABLE organization_unit (
       unit_code         VARCHAR2(5 CHAR)   NOT NULL PRIMARY KEY,
       unit_name         VARCHAR2(100 CHAR) NOT NULL,
       parent_unit_code  VARCHAR2(5 CHAR)  
    CREATE TABLE org_unit_parameters (
       unit_code         VARCHAR2(5 CHAR)   NOT NULL PRIMARY KEY,
       param1            VARCHAR2(100 CHAR),
       param2            VARCHAR2(100 CHAR),
       param3            VARCHAR2(100 CHAR),
       param4            VARCHAR2(100 CHAR)
    -- Inserting data
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code)
    VALUES ('00000', 'Top level', NULL);
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code)
    VALUES ('10', 'L2 unit #10', '00000');
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code)
    VALUES ('10-01', 'L3 unit #10-01', '10');
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code)
    VALUES ('10-02', 'L3 unit #10-02', '10');
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code)
    VALUES ('20', 'L2 unit #20', '00000');
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code)
    VALUES ('20-01', 'L3 unit #20-01', '20');
    INSERT INTO organization_unit (unit_code, unit_name, parent_unit_code)
    VALUES ('20-02', 'L3 unit #20-02', '20');
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param1, param2, param3)
    VALUES ('00000', 'Default value', 'Default value', 'Default value');
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param2, param3)
    VALUES ('10', 'Value from 10', 'Value from 10');
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param3)
    VALUES ('10-01', 'Value from 10-01');
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param4)
    VALUES ('10-02', 'Value from 10-02');
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param1, param2, param3)
    VALUES ('20', 'Value from 20', 'Value from 20', 'Value from 20');
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param2)
    VALUES ('20-01', 'Value from 20-01');
    INSERT INTO ORG_UNIT_PARAMETERS (unit_code, param2)
    VALUES ('20-02', 'Value from 20-02');
    COMMIT;

    Now, I hoppe I got your reqs:
    WITH hierarchy AS (
                       SELECT  ou.unit_code,
                               LPAD(' ',2*(LEVEL-1)) || ou.unit_code    AS tree,
                               LEVEL                                    AS lvl,
                               param1                                   AS param1_raw,
                               param2                                   AS param2_raw,
                               param3                                   AS param3_raw,
                               param4                                   AS param4_raw,
                               SYS_CONNECT_BY_PATH(p.param1,'#') || '#' AS param1_path,
                               SYS_CONNECT_BY_PATH(p.param2,'#') || '#' AS param2_path,
                               SYS_CONNECT_BY_PATH(p.param3,'#') || '#' AS param3_path,
                               SYS_CONNECT_BY_PATH(p.param4,'#') || '#' AS param4_path
                         FROM  organization_unit ou LEFT JOIN org_unit_parameters p
                                 ON ou.unit_code = p.unit_code
                         START WITH parent_unit_code IS NULL
                         CONNECT BY PRIOR ou.unit_code =  parent_unit_code
    SELECT  unit_code,
            tree,
            lvl,
            param1_raw,
            REGEXP_SUBSTR(param1_path,'[^#]+',1,GREATEST(1,REGEXP_COUNT(param1_path,'[^#]+'))) AS param1_with_last,
            REGEXP_SUBSTR(param1_path,'[^#]+')                                                 AS param1_with_first,
            param2_raw,
            REGEXP_SUBSTR(param2_path,'[^#]+',1,GREATEST(1,REGEXP_COUNT(param2_path,'[^#]+'))) AS param2_with_last,
            REGEXP_SUBSTR(param2_path,'[^#]+')                                                 AS param2_with_first,
            param3_raw,
            REGEXP_SUBSTR(param3_path,'[^#]+',1,GREATEST(1,REGEXP_COUNT(param3_path,'[^#]+'))) AS param3_with_last,
            REGEXP_SUBSTR(param3_path,'[^#]+')                                                 AS param3_with_first,
            param4_raw,
            REGEXP_SUBSTR(param4_path,'[^#]+',1,GREATEST(1,REGEXP_COUNT(param4_path,'[^#]+'))) AS param4_with_last,
            REGEXP_SUBSTR(param4_path,'[^#]+')                                                 AS param4_with_first
      FROM  hierarchy
      ORDER BY unit_code
    UNIT_ TREE              LVL PARAM1_RAW       PARAM1_WITH_LAST PARAM1_WITH_FIRS PARAM2_RAW       PARAM2_WITH_LAST PARAM2_WITH_FIRS PARAM3_RAW       PARAM3_WITH_LAST PARAM3_WITH_FIRS PARAM4_RAW       PARAM4_WITH_LAST PARAM4_WITH_FIRS
    00000 00000               1 Default value    Default value    Default value    Default value    Default value    Default value    Default value    Default value    Default value
    10      10                2                  Default value    Default value    Value from 10    Value from 10    Default value    Value from 10    Value from 10    Default value
    10-01     10-01           3                  Default value    Default value                     Value from 10    Default value    Value from 10-01 Value from 10-01 Default value
    10-02     10-02           3                  Default value    Default value                     Value from 10    Default value                     Value from 10    Default value    Value from 10-02 Value from 10-02 Value from 10-02
    20      20                2 Value from 20    Value from 20    Default value    Value from 20    Value from 20    Default value    Value from 20    Value from 20    Default value
    20-01     20-01           3                  Value from 20    Default value    Value from 20-01 Value from 20-01 Default value                     Value from 20    Default value
    20-02     20-02           3                  Value from 20    Default value    Value from 20-02 Value from 20-02 Default value                     Value from 20    Default value
    7 rows selected.
    SQL>  SY.
    Edited by: Solomon Yakobson on Nov 12, 2010 10:09 AM

  • Hierarchies in query and giving authorizations

    Hi All Gurus,
    i need to create  hierarchies in a report , how to create them , why we create them and i need a detailed explanation and and the authorization  .Presenly am working on HR module and i need to create a report where a manager can see only his employee details like ( working hours, actual time and the illness hours ) for his organisational unit. only the respective manager can see only his employee details .Do we need to create the authorizations here can we  have a tree structure to select on?  The user would like to have a tree structure of the managers organization .
    i think i gave an over view  .Kindly could some one expert tell me how to build the structure ,any more info mail me at ([email protected])
    100% points will be awarded .
    Thanks in advance
    Sherwin

    Paul,
    a) Enable the characteristic for hierarchies (sales employee presumably).
    b) Build your hierarchy in R/3 or BW. If you do it in R/3 you need to setup the daily / weekly load of the hierarchy.
    c) In your query set the properties of the characteristic to look at your hierarchy.
    When your hierarchy is built you will setup authorizations at node level - then in your query you will assign the Authorization variable to the Sales Employee characteristic.
    Regards
    Gill

  • Hierarchical SQL query

    Hi
    I'm trying to list out all the responsibilities, menus, sub menus, functions attached to a particular user. I need to write a hierarchical query that will recursively pick up the sub menus within other sub menus and list them all out.
    Any help would be greatly appreciated!
    Thank you,
    VVM

    Sorry about that!
    Wrote this until I realized I would need some recursive query to get all the sub menus,
    SELECT FR.responsibility_key Responsibility , FM.user_menu_name FirstLevelMenu, FM1.user_menu_name SecondLevelMenu, FM2.user_menu_name ThirdLevelMenu
    FROM FND_MENUS_TL FM
    ,fnd_responsibility FR
    ,FND_USER_RESP_GROUPS_DIRECT FURG
    ,FND_MENU_ENTRIES FME1
    ,FND_MENU_ENTRIES FME2
    ,FND_MENUS_TL FM1
    ,FND_MENUS_TL FM2
    WHERE FR.menu_id = FM.menu_id
    AND TRUNC(NVL(FR.end_date,sysdate)) >= TRUNC(sysdate)
    AND FR.responsibility_id = FURG.responsibility_id
    AND FURG.user_id = '0'
    AND TRUNC(NVL(FURG.end_date,sysdate)) >= TRUNC(sysdate)
    AND FME1.menu_id = FM.menu_id
    AND FME1.sub_menu_id = FM1.menu_id
    AND FME2.menu_id = FM.menu_id
    AND FME2.sub_menu_id = FM2.menu_id
    group BY FR.responsibility_key, FM.user_menu_name, FM1.user_menu_name, FM2.user_menu_name
    -VVM

  • How can I create a materialized view based on hierarchical cube query?

    Hi,
    database version 10gR2.
    When i try to create MV for sql below, i got error .
    I tried creating MV log in several ways, but still, keep getting the same error.
    SQL Error: ORA-12015: cannot create a fast refresh materialized view from a complex query
    12015. 00000 -  "cannot create a fast refresh materialized view from a complex query"
    *Cause:    Neither ROWIDs and nor primary key constraints are supported for
               complex queries.
    *Action:   Reissue the command with the REFRESH FORCE or REFRESH COMPLETE
               option or create a simple materialized view.So, I wonder if it is possible to create MV based on sql below?
    if yes, how should I do it?
    if no, what is the alternative?
    select
          coalesce(UP_ORG_ID_6, UP_ORG_ID_5, UP_ORG_ID_4, UP_ORG_ID_3, UP_ORG_ID_2, UP_ORG_ID_1) as ORG_ID,
          a.day_id as day_id,     
          a.TRADE_TYPE_ID as TRADE_TYPE_ID,
          a.CUST_ID,
          coalesce(UP_CODE_6, UP_CODE_5, UP_CODE_4, UP_CODE_3, UP_CODE_2, UP_CODE_1) as product_id,
          QUANTITY_UNIT,
          COST_UNIT,
          A.SOURCE_ID as SOURCE_ID,
          SUM(CONTRACT_AMOUNT) as CONTRACT_AMOUNT,
          SUM(CONTRACT_COST) as CONTRACT_COST,
          SUM(SALE_AMOUNT) as SALE_AMOUNT,
          SUM(SALE_COST) as SALE_COST,
          SUM(ACTUAL_AMOUNT) as ACTUAL_AMOUNT,
          SUM(ACTUAL_COST) as ACTUAL_COST,
          SUM(TRADE_COUNT) as TRADE_COUNT     
    from DM_F_LO_SALE_DAY a, DM_D_ALL_ORG_FLAT B, DM_D_ALL_PROD_FLAT D
    where a.ORG_ID=B.ORG_ID
          and a.PRODUCT_ID=D.CODE
          and a.day_id=20110201
    group by rollup(UP_ORG_ID_1, UP_ORG_ID_2, UP_ORG_ID_3, UP_ORG_ID_4, UP_ORG_ID_5, UP_ORG_ID_6),
          a.TRADE_TYPE_ID,
             a.day_id,
          A.CUST_ID,
          rollup(UP_CODE_1, UP_CODE_2, UP_CODE_3, UP_CODE_4, UP_CODE_5, UP_CODE_6),
          a.QUANTITY_UNIT,
          a.COST_UNIT,
          a.SOURCE_ID;Thanks in advance.

    Rob vanWjik has an excellent series of fast refresh materialized views starting here:
    http://rwijk.blogspot.com/2009/05/fast-refreshable-materialized-view.html
    Part three specifically on aggregate MVs is here:
    http://rwijk.blogspot.com/2009/06/fast-refreshable-materialized-view.html

  • Hierarchical sys_connect_by_path query needing to process child results

    Application Express 4.0.2.00.06 - DB 10.2
    Hello all!
    I work for an organization having rooms, each with a defined relationship to some or all of the other rooms (some higher, some lower) which must be observed by personnel moving between them.
    I've been tasked with writing an page(extending an existing app in which the relationships are managed) in which if a user provide a list of rooms they wish to visit, a list of hierarchy options will be provided based on the relationship rules between rooms.
    It is implied that given a sourcename/destname pair, sourcename can go to destname and the inverse is also true (destname can come/receive from sourcename)
    This is my sample data set (heavily filtered from actual data);
    SOURCE_ROOMID     SOURCENAME     DEST_ROOMID     DESTNAME
    28          Ax1          76          G3A
    28          Ax1          27          FGB44
    58          MP23          27          FGB44
    58          MP23          104          MP22
    58          MP23          76          G3A
    76          G3A          27          FGB44
    104          MP22          76          G3A
    104          MP22          58          MP23Using this query, I'm able to build the beginning of my hierarchy.
    SELECT DISTINCT source_roomid,
                    sourcename,
                    dest_roomid,
                    destname,
                    sourcename|| ',' ||REVERSE(sys_connect_by_path(REVERSE(destname),',')) path,
                    (REVERSE(sys_connect_by_path(REVERSE(sourcename),',')))parents,
                    (REVERSE(sys_connect_by_path(REVERSE(destname),',')))children
    FROM           (SELECT source_roomid, A.NAME AS sourcename, dest_roomid, b.NAME AS destname
                    FROM   rm_approved_room_state, rm_room A, rm_room b
                    WHERE  source_roomid IN (27, 28, 58, 76, 104)
                    AND    dest_roomid IN (27, 28, 58, 76, 104)
                    AND    a.roomid = source_roomid
                    AND    b.roomid = dest_roomid)
    --START WITH     source_roomid IN (27, 28, 58, 76, 104)
    CONNECT BY NOCYCLE PRIOR source_roomid = dest_roomid
    order by 1And my initial result set is:
    SOURCE_ROOMID     SOURCENAME     DEST_ROOMID     DESTNAME     PATH               PARENTS          CHILDREN     
    28          Ax1          27          FGB44          Ax1,FGB44,          Ax1,          FGB44,
    28          Ax1          76          G3A          Ax1,G3A,          Ax1,          G3A,
    28          Ax1          76          G3A          Ax1,G3A,FGB44,          Ax1,G3A,     G3A,FGB44,
    58          MP23          27          FGB44          MP23,FGB44,          MP23,          FGB44,
    58          MP23          76          G3A          MP23,G3A,          MP23,          G3A,
    58          MP23          76          G3A          MP23,G3A,FGB44,          MP23,G3A,     G3A,FGB44,
    58          MP23          104          MP22          MP23,MP22,          MP23,          MP22,
    58          MP23          104          MP22          MP23,MP22,G3A,          MP23,MP22,     MP22,G3A,
    58          MP23          104          MP22          MP23,MP22,G3A,FGB44,     MP23,MP22,G3A,     MP22,G3A,FGB44,
    58          MP23          104          MP22          MP23,MP22,MP23,          MP23,MP22,     MP22,MP23,
    76          G3A          27          FGB44          G3A,FGB44,          G3A,          FGB44,
    104          MP22          58          MP23          MP22,MP23,          MP22,          MP23,
    104          MP22          58          MP23          MP22,MP23,FGB44,     MP22,MP23,     MP23,FGB44,
    104          MP22          58          MP23          MP22,MP23,G3A,          MP22,MP23,     MP23,G3A,
    104          MP22          58          MP23          MP22,MP23,G3A,FGB44,     MP22,MP23,G3A,     MP23,G3A,FGB44,
    104          MP22          58          MP23          MP22,MP23,MP22,          MP22,MP23,     MP23,MP22,
    104          MP22          76          G3A          MP22,G3A,          MP22,          G3A,
    104          MP22          76          G3A          MP22,G3A,FGB44,          MP22,G3A,     G3A,FGB44,The challenge for me is that for the hierarchy to be correct, every hierarchy row where level >= 2 needs a check to determine if the latest child can receive from the previous child otherwise filter those lines out. Also, paths where there is duplicated data needs to be removed leaving the longest heirarchy intact.
    SOURCE_ROOMID     SOURCENAME     DEST_ROOMID     DESTNAME     PATH               PARENTS          CHILDREN     
    28          Ax1          27          FGB44          Ax1,FGB44,          Ax1,          FGB44,
      (****THE NEXT LINE IS NOT NECESSARY BECAUSE THE NEXT LINE ALREADY CONTAINS THIS HIERARCHY DATA****)
    28          Ax1          76          G3A          Ax1,G3A,          Ax1,          G3A,
    28          Ax1          76          G3A          Ax1,G3A,FGB44,          Ax1,G3A,     G3A,FGB44,I also need to pull out instances of where rooms related to each other as in this case.
    SOURCE_ROOMID     SOURCENAME     DEST_ROOMID     DESTNAME     PATH               PARENTS          CHILDREN
    104          MP22          58          MP23          MP22,MP23,MP22,          MP22,MP23,     MP23,MP22,Leaving this as the anticipated output.
    SOURCE_ROOMID     SOURCENAME     DEST_ROOMID     DESTNAME     PATH               PARENTS          CHILDREN     
    28          Ax1          27          FGB44          Ax1,FGB44,          Ax1,          FGB44,
    28          Ax1          76          G3A          Ax1,G3A,FGB44,          Ax1,G3A,     G3A,FGB44,
    58          MP23          27          FGB44          MP23,FGB44,          MP23,          FGB44,
    58          MP23          76          G3A          MP23,G3A,FGB44,          MP23,G3A,     G3A,FGB44,
    58          MP23          104          MP22          MP23,MP22,G3A,          MP23,MP22,     MP22,G3A,
    76          G3A          27          FGB44          G3A,FGB44,          G3A,          FGB44,
    104          MP22          58          MP23          MP22,MP23,G3A,          MP22,MP23,     MP23,G3A,
    104          MP22          76          G3A          MP22,G3A,          MP22,          G3A,Any thoughts on how I might get these last three things done in my hierarchy example?
    Many thanks in advance!
    Paul
    Edited by: pgtaviator on Nov 9, 2011 4:34 PM

    Hi, Paul,
    Sorry, it's unclear what you want.
    pgtaviator wrote:
    Application Express 4.0.2.00.06 - DB 10.2
    Hello all!
    I work for an organization having rooms, each with a defined relationship to some or all of the other rooms (some higher, some lower) which must be observed by personnel moving between them.
    I've been tasked with writing an page(extending an existing app in which the relationships are managed) in which if a user provide a list of rooms they wish to visit, a list of hierarchy options will be provided based on the relationship rules between rooms.
    It is implied that given a sourcename/destname pair, sourcename can go to destname and the inverse is also true (destname can come/receive from sourcename)If "the inverse is also true", why don't the desired results include any paths such as
    G3A,Ax1     or
    FGB44,MP23,MP22     ?
    This is my sample data set (heavily filtered from actual data);
    SOURCE_ROOMID     SOURCENAME     DEST_ROOMID     DESTNAME
    28          Ax1          76          G3A
    28          Ax1          27          FGB44
    58          MP23          27          FGB44
    58          MP23          104          MP22
    58          MP23          76          G3A
    76          G3A          27          FGB44
    104          MP22          76          G3A
    104          MP22          58          MP23
    Please post CREATE TABLE and INSERT statements for the sample data.
    Is this de-normalized data? That is, does roomid=28 always correspond to name='Ax1', and name='Ax1' always correspond to roomid=28? If not, include examples in your sample data and results, and explain.
    Using this query, I'm able to build the beginning of my hierarchy.
    SELECT DISTINCT source_roomid,
    sourcename,
    dest_roomid,
    destname,
    sourcename|| ',' ||REVERSE(sys_connect_by_path(REVERSE(destname),',')) path,
    (REVERSE(sys_connect_by_path(REVERSE(sourcename),',')))parents,
    (REVERSE(sys_connect_by_path(REVERSE(destname),',')))children
    FROM           (SELECT source_roomid, A.NAME AS sourcename, dest_roomid, b.NAME AS destname
    FROM   rm_approved_room_state, rm_room A, rm_room b
    WHERE  source_roomid IN (27, 28, 58, 76, 104)
    AND    dest_roomid IN (27, 28, 58, 76, 104)
    AND    a.roomid = source_roomid
    AND    b.roomid = dest_roomid)
    --START WITH     source_roomid IN (27, 28, 58, 76, 104)
    CONNECT BY NOCYCLE PRIOR source_roomid = dest_roomid
    order by 1
    Thanks for posting the existing query; that's very helpful.
    REVERSE is not a documented Oracle function. Using undocumneted functions isn't a very good idea. In this case, can't you just change the CONNECT BY clause to:
    CONNECT BY NOCYCLE       source_roomid = PRIOR dest_roomidto get the results you want?
    And my initial result set is:
    SOURCE_ROOMID     SOURCENAME     DEST_ROOMID     DESTNAME     PATH               PARENTS          CHILDREN     
    28          Ax1          27          FGB44          Ax1,FGB44,          Ax1,          FGB44,
    28          Ax1          76          G3A          Ax1,G3A,          Ax1,          G3A,
    28          Ax1          76          G3A          Ax1,G3A,FGB44,          Ax1,G3A,     G3A,FGB44,
    58          MP23          27          FGB44          MP23,FGB44,          MP23,          FGB44,
    58          MP23          76          G3A          MP23,G3A,          MP23,          G3A,
    58          MP23          76          G3A          MP23,G3A,FGB44,          MP23,G3A,     G3A,FGB44,
    58          MP23          104          MP22          MP23,MP22,          MP23,          MP22,
    58          MP23          104          MP22          MP23,MP22,G3A,          MP23,MP22,     MP22,G3A,
    58          MP23          104          MP22          MP23,MP22,G3A,FGB44,     MP23,MP22,G3A,     MP22,G3A,FGB44,
    58          MP23          104          MP22          MP23,MP22,MP23,          MP23,MP22,     MP22,MP23,
    76          G3A          27          FGB44          G3A,FGB44,          G3A,          FGB44,
    104          MP22          58          MP23          MP22,MP23,          MP22,          MP23,
    104          MP22          58          MP23          MP22,MP23,FGB44,     MP22,MP23,     MP23,FGB44,
    104          MP22          58          MP23          MP22,MP23,G3A,          MP22,MP23,     MP23,G3A,
    104          MP22          58          MP23          MP22,MP23,G3A,FGB44,     MP22,MP23,G3A,     MP23,G3A,FGB44,
    104          MP22          58          MP23          MP22,MP23,MP22,          MP22,MP23,     MP23,MP22,
    104          MP22          76          G3A          MP22,G3A,          MP22,          G3A,
    104          MP22          76          G3A          MP22,G3A,FGB44,          MP22,G3A,     G3A,FGB44,The challenge for me is that for the hierarchy to be correct, every hierarchy row where level >= 2 needs a check to determine if the latest child can receive from the previous child otherwise filter those lines out.I don't understand the requirement above at all.
    Also, paths where there is duplicated data needs to be removed leaving the longest heirarchy intact.
    SOURCE_ROOMID     SOURCENAME     DEST_ROOMID     DESTNAME     PATH               PARENTS          CHILDREN     
    28          Ax1          27          FGB44          Ax1,FGB44,          Ax1,          FGB44,
    (****THE NEXT LINE IS NOT NECESSARY BECAUSE THE NEXT LINE ALREADY CONTAINS THIS HIERARCHY DATA****)
    28          Ax1          76          G3A          Ax1,G3A,          Ax1,          G3A,
    28          Ax1          76          G3A          Ax1,G3A,FGB44,          Ax1,G3A,     G3A,FGB44,
    Are you using "THE NEXT LINE" to mean 2 different things? Do you mean "The line with Ax1,G3A is not wanted because it is a sub-path of Ax1,G3A,FGB44"?
    Why do the desired results include
    MP22,G3A     (which is a sub-path of MP23.MP22,G3A) and
    G3A,FGB44     (which is a sub-path of both Ax1,G3A,FGB44 and MP23,G3A,FGB44)?
    I also need to pull out instances of where rooms related to each other as in this case.
    SOURCE_ROOMID     SOURCENAME     DEST_ROOMID     DESTNAME     PATH               PARENTS          CHILDREN
    104          MP22          58          MP23          MP22,MP23,MP22,          MP22,MP23,     MP23,MP22,
    When you way "rooms related to each other", do you mean "rooms related to themselves"? It looks like you're saying that no room can occur 2 (or more) times in any path.
    Leaving this as the anticipated output.
    SOURCE_ROOMID     SOURCENAME     DEST_ROOMID     DESTNAME     PATH               PARENTS          CHILDREN     
    28          Ax1          27          FGB44          Ax1,FGB44,          Ax1,          FGB44,
    28          Ax1          76          G3A          Ax1,G3A,FGB44,          Ax1,G3A,     G3A,FGB44,
    58          MP23          27          FGB44          MP23,FGB44,          MP23,          FGB44,
    58          MP23          76          G3A          MP23,G3A,FGB44,          MP23,G3A,     G3A,FGB44,
    58          MP23          104          MP22          MP23,MP22,G3A,          MP23,MP22,     MP22,G3A,
    76          G3A          27          FGB44          G3A,FGB44,          G3A,          FGB44,
    104          MP22          58          MP23          MP22,MP23,G3A,          MP22,MP23,     MP23,G3A,
    104          MP22          76          G3A          MP22,G3A,          MP22,          G3A,
    Why do 3 of the paths end at G3A? Why don't they continue to FGB44 as 2 of the paths do?
    Why is MP23,G3A,FGB44 in the desired output, and not MP22,MP23,G3A,FGB44 (which is longer)?
    Why isn't MP22,MP23,FGB44 in the desired results, but its sub-path MP23,FGB44 is?
    Try describing what you're trying to show in this query, and what each row of the desired result set represents. As far as possible, avoid repeating the explanation you're already used. (Not that there's anything wrong with what you've said so far; it's just that I need all the help I can get to understand the probhlem.)
    Any thoughts on how I might get these last three things done in my hierarchy example?It looks like CONNECT_BY_ISLEAF, and maybe CONNECT_BY_ISCYCLE could help in this problem.
    Regular expressions, or perhaps LIKE, might help in detecting if one path contains another.
    Many thanks in advance!
    Paul
    Edited by: pgtaviator on Nov 9, 2011 4:34 PM

  • HIERARCHIES ON QUERY DESIGNER

    Hi Guys!
    I have a 0ITEM hierarchy with 8 levels, i need to display only from level 4 to level 8 on query designer 7.1, can somebody help me with this?
    Thanx and Regards

    I am not sure if you can do that - level 4 would mean that you expand till level 4 which is essentially 1-4 and if you want level 8 then it is essentially level 1-8.
    You might want to think of changing the hierarchy structure and maybe merging the first 4 levels of your hierarchy - store this as a separate hierarchy and then use that in your query.
    Arun

  • Hierarchical tree query

    dear all,
    plz can you explain to me what is this query mean
    plz i need it piece by piece
    rg_emps := Create_Group_From_Query('rg_emps','select 1, level,last_name, NULL, to_char(employee_id) '||' from employees '   ||'connect by prior employee_id = manager_id ' ||'start with job_id = ''AD_PRES''');i exactly need this part
    select 1, level, last_name, null
    how could you select null (oooooooh )
    plz help & advice

    hi
    here is an example:
    select -1 , level , ename , null , to_char(empno)
    from emp start with mgr is null
    connect by prior empno = mgror
    select 1 , level , ename , null , to_char(empno)
    from emp start with mgr is null
    connect by prior empno = mgrsarah
    Edited by: QGIRCO on Jan 17, 2010 10:27 PM

  • Help with a VERY DIFFICULT Query.  Anyone up for the task?

    Hi, I have been struggling with this query for a week now and have made a little progress but not much: I apoligize for the long post but it needs explanation. Let me set up the question first.
    I have a query that needs to run for a crystal report graph per supplier. This report is run ONCE per supplier(per record) and will return the current supplier's name, commodity(manufacturing part type) and index points(parts that have failures). It will also return all of the other suppliers with the same commodity, their index points, and a BLANK entry for their supplier name. The purpose of this is so that the supplier can see our companies ranking of suppliers by commodity, but should only know where they are ranked, not other suppliers. So in the bar graph legend, on the x-axis all you will see is a single label(the report's current record...supplier). Now for the table setup.
    The query pulls from three tables:
    1. VEN_LOC , master supplier table, includes all of our supplier's ID's(PK) and names
    2. C_VENCOM , detached table, includes all of our supplier's ID's and commodity PK is (SupplierID,commodity)
    3. QA_OCC , detached table, entries in this table are only inserted when there is a failure occurrence(index points). If a supplier does not have any failures during a specific date range (column OCCDATE) then there will be no records for that supplier in this table...this is where my problem comes from. Please read to end to understand problem.
    Now for the query. Notice the union...the first part returns the current supplier's ID, name, commodity, and indexpoints. The second half of the query is what returns every other supplier with the same commodity, but returns '' for the supplier's name:
    select supname,commodity,ip from(
    select supname,commodity,ip from
    (select v.name as supname, c.commodity, sum(q.indexpoints+q.lateindexpoints) as ip
    from qa_occ q, c_vencom c, ven_loc v
    where q.occdate between to_date('4/1/2006','mm/dd/yyyy')
    and to_date('3/31/2007','mm/dd/yyyy')
    and v.vendor='10063'
    and v.vendor=c.vendor
    and c.vendor=q.supplier
    and v.ven_loc=c.pur_loc
    and c.pur_loc=q.SUPPLIERLOC
    group by v.name, c.commodity)
    union
    select '' as supname,commodity,ip from
    (select v.name as supname, c.commodity, sum(q.indexpoints+q.lateindexpoints) as ip
    from qa_occ q, c_vencom c, ven_loc v
    where q.occdate between to_date('4/1/2006','mm/dd/yyyy')
    and to_date('3/31/2007','mm/dd/yyyy')
    and v.vendor<>'10063'
    and v.vendor=c.vendor
    and c.vendor=q.supplier
    group by v.name, c.commodity)
    order by commodity, ip desc) qa
    where qa.commodity in (
    select commodity from c_vencom
    where vendor='10063')
    group by commodity,supname,ip
    order by commodity,supname,ip
    This will return the following recordset:
    SUPNAME      COMMODITY     IP
    KF Corp.      FASTENER     63
         FASTENER     12
         FASTENER     33
         FASTENER     126
         FASTENER     153
    KF Corp.      RUBBER      63
         RUBBER     12
         RUBBER      226
         RUBBER      259
    This works like it should....
    But... Here is where it gets really really tricky for me and the problem. Even if a supplier has no index points for a given date range, I still have to return a recordset with the supplier's name, commodity, and indexpoints of zero along with all other suppliers but names as ''.
    So.. for example, one of our suppliers with ID# 10143 has no index points during the date range 4/1/2006-3/31/2007 so there are zero entries for this supplier in QA_OCC. Therefore the query returns only the other suppliers with this commodity but without 10143's suppliername, commodity, or index points of zero. so:
    SUPNAME     COMMODITY     IP
         PLASTIC      12
         PLASTIC      45
         PLASTIC      51
         PLASTIC      78
    When it should return no matter what:
    SUPNAME     COMMODITY     IP
    Emhart PLASTIC 0
         PLASTIC      12
         PLASTIC      45
         PLASTIC      51
         PLASTIC      78
    Understand? If you need further info don't hesitate to e-mail me at [email protected]. Thank you.
    Eric

    Thanks but it doesnt change the results. Still not returning the supplier that has no records in QA_OCC..HOWEVER it is returning an extra result, still without name or 0 indexpoints though
    SUPNAME     COMMODITY     IP
         PLASTIC     12
         PLASTIC     45
         PLASTIC     51
         PLASTIC     78
         PLASTIC     
    select supname,commodity,ip from(
    select supname,commodity,ip from
    select v.name as supname, c.commodity, sum(q.indexpoints+q.lateindexpoints) as ip
    from qa_occ q right outer join glovia_prod.c_vencom@gl7test c
    on q.occdate between to_date('4/1/2006','mm/dd/yyyy')
    and to_date ('3/31/2007','mm/dd/yyyy')
    and c.vendor=q.supplier
    join glovia_prod.ven_loc v on v.vendor=c.vendor
    -- from qa_occ q, glovia_prod.c_vencom@gl7test c, glovia_prod.ven_loc v
    --where q.occdate between to_date('4/1/2006','mm/dd/yyyy')
    -- and to_date('3/31/2007','mm/dd/yyyy')
    and v.vendor='10143'
    -- and v.vendor=c.vendor
    -- and c.vendor=q.supplier
    and v.ven_loc=c.pur_loc
    and c.pur_loc=q.SUPPLIERLOC
    group by v.name, c.commodity)
    union
    select '' as supname,commodity,ip from
    (select v.name as supname, c.commodity, sum(q.indexpoints+q.lateindexpoints) as ip
    from qa_occ q right outer join glovia_prod.c_vencom@gl7test c
    on q.occdate between to_date('4/1/2006','mm/dd/yyyy')
    and to_date ('3/31/2007','mm/dd/yyyy')
    and c.vendor=q.supplier
    join glovia_prod.ven_loc v on v.vendor=c.vendor
    and v.vendor<>'10143'
    group by v.name, c.commodity)
    order by commodity, ip desc) qa
    where qa.commodity in (
    select commodity from glovia_prod.c_vencom@gl7test
    where vendor='10143')
    group by commodity,supname,ip
    order by commodity,supname,ip

  • Hierarchical query with where clause

    Hi,
    How can I query hierarchically a query with WHERE clause? I have a table with three fields session_id,id and root_id.
    When I try with the following query,
    select id, level from relation
    where session_id = 79977
    connect by prior id = root_id start with id = 5042;
    It gets duplicate values.
    I want the query to show in the hierarchical manner with a filter condition using WHERE clause. Please help me how can I achieve this. If you know any link that describes more about this, please send it.
    Thanks in Advance.
    Regards,
    -Parmy

    Hi Sridhar Murthy an others,
    Thanks a lot for your/the answer. It's working for me. It saved a lot of other work around without the proper knowledge of hierarchical query. Please send me any link that describes these issues in detail and also I hope as I have mentioned in the other message, same cannot be achieved on views or ( on two different tables ???)
    Any way thanks for your reply,
    It's working for me.
    With happiness,
    -Parmy

  • Issue with hierarchy node variable and multiple SAP hierarchies

    Hello experts,
    We are currently facing an issue when using two SAP hierarchies in Web Intelligence and one of them is restricted with a hierarchy node variable.
    The systems we use are a SAP BI 7.01 (SPS 05) and a Business Objects Enterprise XI R3.1 SP2 (fix pack 2.3). I want also to point out that the fix pack 2.3 has been applied to all BOE related components: the SAP integration Kit, client tools, and enterprise (server and client).
    The universe used in our scenario is based on a BEX Query with two hierarchies (non-time dependent hierarchies, intervals allowed) loaded on their corresponding characteristics. One of these characteristics is restricted with a hierarchy node variable (manual input, optional, ready for input, multiple single values allowed). 
    Prerequisites for replicating the problem:
    1)     When building the web intelligence query select several levels from both hierarchies (they have seven levels each) and    the   only amount of the InfoCube that the BEX query (that was used to create our universe) relies on.
    2)     In the hierarchy node variable prompt select a hierarchy node entry (not an actual InfoObject value that exists as transactional data in the InfoCube )
    By executing the query built above, all characteristics are returned null (no value) and the key figure with value u201C0u201D. No error messages, no partial results warnings.  Now if we go back to u201CEdit queryu201D and select levels of only one of any of the two hierarchies the query runs normally (by selecting the exact same value for the hierarchy node variable prompt).
    Any ideas on the matter?
    Regards,
    Giorgos

    Hi,
    Have you ever got a solution for this problem?
    I have a similar one.
    Thanks,
    regards, Heike

  • Help in writing a query!

    Dear All,
    My database is 11gR2 on Linux.
    I am struck in writing a difficult query, need help from your guys.
    I have a table, an application is controlling the columns of this table. Columns are added by the application.
    This is the structure of the table:
    create table imran_test(
    2 username varchar2(100),
    3 layer1 number(1),
    4 layer2 number(2),
    5 layer3 number(2));
    -- where layer1, layer2, layer3.... are increased up to layer 22 and could be increased more...
    Now each username will have 1 in any one of the layer, and all other layers will have 0
    Like if I consider the above table this could be the sample data:
    imran 1 0 0
    hafeez 0 1 0
    james 0 0 1
    Now the result my query should return is:
    select username, <column name where value is 1> and value of it, as per sample data, this should be return by the query:
    imran layer1 1
    hafeez layer2 1
    james layer 3 1
    Note: Please remember the columns are not fixed, they are added/altered by application.
    Regards,
    Imran

    The table design is incorrect as it is not in 3NF and has a repeating group
    You should correct the 'design' first or turn the layer... columns in a VARRAY.
    Also my feeling is you should change your subject line 'Help in writing a query!' in 'Write my query' as that is what you actually ask, and leave out the exclamation mark.
    Basically you dump everything in this forum, and being a bit less demanding might suit you better.
    Also you still act rude by not marking your questions as answered.
    Change that
    Sybrand Bakker
    Senior Oracle DBA
    Edited by: sybrand_b on 1-apr-2012 12:09

  • Using a WHERE clause in APEX Tree

    Hi All -
    I have an hierarchical SQL query that I'm displaying as an APEX tree.
    My sample app is here:
    https://apex.oracle.com/pls/apex/f?p=32581:29
    login: guest
    pw: app_1000
    workspace: leppard
    I am trying to add a WHERE clause so that only nodes with the lowest level children are displayed, i.e. something like 'WHERE connect_by_isleaf = 0 OR level = 5'
    The tree query with the where clause works fine in the SQL commands window, but when I add the WHERE clause to my apex tree the page no longer displays anything. Is this an issue with APEX or is there some other way to filter my results?
    Thanks in advance for any suggestions,
    john

    Connect by occurs first, the where clause then is applied to those results, effectively cutting away in the hierarchical structure. Since apex has to build a hierarchical structure from the query it relies on the level pseudocolumn, which is butchered by applying the where clause. It's a miracle you aren't even receiving errors because I'd almost expect an incorrect json array to have been built. With no top level to start from and only level 5 or leaf nodes there is no structure to present: both apex can not put out a correct representation and not jstree either. In your query you will see your "root nodes" but it is not representable.
    I'm not sure why you want to present this in a tree? Both connect_by_is_leaf and level = 5 will simply give you a list of nodes without any hierarchical structure.
    The better thing to do is to use a subquery to first limit your dataset and then use that to base the tree query on, that way you don't break any of those vital columns.
    Eg if you only want leaf nodes and their immediate parent you could go for something like this (quick mockup on some testdata):
    with dataset as (
    select node_id, parent_id
       from treedata
      where connect_by_isleaf = 0
    connect by prior node_id = parent_id
      start with parent_id = 0
    dataset2 as (
    select node_id, parent_id
      from dataset
    union all
    select node_id, null parent_id
      from treedata
    where node_id in (select parent_id from dataset)
    select level, node_id
       from dataset2
    connect by prior node_id = parent_id
      start with parent_id is null

  • How to check the selected items of a selectManyListbox in doDML of an EO ?

    Hello,
    I have a VO based on en EO. During the doDML(UPDATE) of that EO, I would like to check what items of a af:selectManyListbox have been selected.
    How could I get the checked items in the selectManyListbox (which belongs to the ViewController) in the doDML method of an EO (which belongs to the Model)?
    Many thanks

    Hello John,
    I know I cannot access the component directly. This is why I asked my question.
    The real case is rather complex and long to be copied and pasted here.
    Let me simplify it without being too generic.
    The VO is based on a hierarchical SQL query. All its EO attributes are transient. This VO is shown as a Tree in the page.
    Each node of the Tree has a checkBox. During commit (doDML() of the EO to be precise), for each checked node I need to access the selected items of a selectManyListbox in some proper way to perform further operations on the DB (no matter what now). The selectManyListbox is based on a second VO. As you may understand, the problem is that from the EO I don't have a direct access to the selectManyListbox. Also, as far as I know, the VO the selectManuListBox is based on does not have any informations about the selected elements, since the checkBox in the list cannot be associated to the VO. Basically I cannot know what elements have been choosen.
    I hope the problem is clear.

  • Call hierarchy issue in APD

    Hi BW Gurus,
    we have a requirement in which we need to provide CSV files based on query in APD
    When checked using each query I am getting a short dump stating u201CCall hierarchy issueu201D(hierarchies are used in query)
    And when I remove the hierarchy in query u2026I am able to execute the APDu2026and generate the fileu2026but some key figures are restricted with hierarchies which should not be removedu2026..is there any concern in using hierarchies of Query in APDu2026is there any other alternative
    Please let me know
    Regards,
    Srivatsava

    Hi Kiran/Riyez,
    Thanks for your inputs,
    But requirement is to send finance data as CSV files, so we have to use existing queries built on COPA cubes, here we canu2019t remove hierarchies
    I have checked query by executing separately its running fine, while trying with APD we are getting this DUMP

Maybe you are looking for

  • Everything has disappeared from my iTunes...

    The problem listed above, is one of many Been having, what looks to be, a common problem with my iPhone 4 - I suddenly keep getting a warning message telling me that I'm running out of storage on the phone and I should go to settings to change my sto

  • How to Import Vector Identified Files into Photoshop Without Losing Quality

    Hello, I am creating a series of music worksheets on photoshop. I have created some music scores in a music writing software called Sibelius 7. It has the capability to export the sheet music graphics in the following forms: .pdf, .eps, .bmp, .tiff,

  • Movement type error for Service Processes

    Hi All, We are working on service scenario with CRM5.0 and R/34.6c. The problem that we face is as follows, Whenever we make a service confirmation with products with item cat group BANC the movement type is correctly determined as 261 but whenever o

  • Mail Control - Transport Rule Predicate "RecipientAddressContainsWords"

    "RecipientAddressContainsWords" uses a Words type predicate property. Below is the explanation of the usage and limitation of the Words type property: The Words property accepts one string or an array of strings. It's used in all predicates that insp

  • G++ Installation

    Hi I need to use a C++ compiler on my Sun Netra X1 box running Solaris 8.x. I am not able to any installed on the machine. I tried downloading gcc compliler from sunfreeware.com. But after unzipping the file gcc-3.0-sol8-sparc-local.gz, I end up with