ORACLE

ORACLE
Let us share our knowledge to the world of oracle apps. I am trying my best to do so and I request every one to contribute their part. If you have any thing useful related to oracle apps, do send me I will post in my blog on behalf of you. If you like my blog tell the world about it, else tell me i will improve. You can suggest me, what exactly you want on oracle apps. Mail your queries.

Wednesday, March 5, 2014

Hierarchical Queries

CONNECT BY
--Query with all the childs

         SELECT fh.parent_flex_value,
          fh.child_flex_value_low low_value,
          fh.child_flex_value_high high_value,
          fh.range_attribute --, level
        FROM fnd_flex_value_norm_hierarchy fh
        WHERE fh.flex_value_set_id =
          (SELECT fvs.flex_value_set_id
           FROM fnd_flex_value_sets fvs
           WHERE fvs.flex_value_set_name = p_value_set
           AND rownum = 1)
        START WITH fh.parent_flex_value = p_value CONNECT BY PRIOR fh.child_flex_value_low = fh.parent_flex_value;

--Query with all the child ranges

        WITH accounts AS
              (SELECT temp.low_value,
                      temp.high_value
               FROM (SELECT fh.parent_flex_value,
                            fh.child_flex_value_low low_value,
                            fh.child_flex_value_high high_value,
                            fh.range_attribute
                      FROM fnd_flex_value_norm_hierarchy fh,
                           fnd_flex_value_sets fvs
                      WHERE fh.flex_value_set_id = fvs.flex_value_set_id
                        AND fvs.flex_value_set_name = 'GlobalCostCentre'
                 START WITH fh.parent_flex_value = :p_value
           CONNECT BY PRIOR fh.child_flex_value_low = fh.parent_flex_value) temp)
        SELECT fv.flex_value,
                 fv.summary_flag
          FROM fnd_flex_values fv,
               fnd_flex_value_sets fvs,
               accounts acc
         WHERE fv.flex_value_set_id = fvs.flex_value_set_id
           AND fvs.flex_value_set_name = 'GlobalCostCentre'
           AND fv.flex_value BETWEEN acc.low_value
                                 AND acc.high_value
           AND fv.enabled_flag = 'Y'
           AND SYSDATE BETWEEN NVL(fv.start_date_active,   SYSDATE)
                           AND NVL(fv.end_date_active,   SYSDATE)
        UNION
        SELECT fv.flex_value,
                  fv.summary_flag
          FROM fnd_flex_value_sets fvs,
               fnd_flex_values fv
         WHERE fvs.flex_value_set_name = 'GlobalCostCentre' --- GlobalAccount
           AND fvs.flex_value_set_id = fv.flex_value_set_id
           AND fv.flex_value = :p_value
           AND fv.enabled_flag = 'Y'
           AND SYSDATE BETWEEN NVL(fv.start_date_active,   SYSDATE)
           AND NVL(fv.end_date_active,   SYSDATE);

No comments:

Post a Comment