Analytical Functions: Parent/child bucketing (distribution)

OK here is an interest problem for the analytical functions hardcore users. I have a parent and child tables. A parent record can have N number of child records. The child table has a FK to the parent table so all child records have a parent. I need to distribute my parents into an N number of buckets based on the number of children they have. The number of buckets will be variable and user-defined. Each bucket should have a similar number of child records but the number of parents is not important. Here a simple output example with 6 parents using 3 buckets of 10 children each:
Parent   Number_Of_Children           Bucket
1        5                            1
2        5                            1
3        6                            2
4        3                            2
5        1                            2
6        4                            3At first this looks like an easy job for the NTILE analytical function to bucket the child records. Another solution could be to use the ROW_NUMBER analytical function to number every child record and then use the WIDTH_BUCKET analytical function to bucket the parents based on their children ROW_NUMBER's value. But there is an additional requirement that makes these 2 approaches unusable. When doing the bucket distribution I need to guarantee that all children from the same parent are bucketed into the same bucket. This obviously makes it much more difficult. The distribution will obviously leave non-equiheight buckets since there will be no guarantee I can fill all my buckets with the same number of child records. Small differences are aceptable however. The distribution can be random and doesn't need to be the best possible distribution (the one that will cause the buckets to be as equiheight as possible). Finally this needs to be a SQL query not PL/SQL. Thanks

Thanks Frank, that was very helpful. I did some research on bin packing and indeed there doesn't seem to be a SQL solution for this kind of problem. Lucky for me some of my requirements are slightly different to the bin packing problem so I was able to come up with something that works. My requirements are that I need to bucket the data by the number of bins rather than by the size of the buckets (unlike most bin packing problems where the size of the bin is fixed). So the bin's size will based on the total number of children divided by the number of desired buckets. The buckets don't have to (and probably won't be) of the same size given that parents can have N number of children. Furthermore we are not lucking to fill the buckets as much as possible, small differences are OK. Based on the above I came up with the following solution.
1) I calculate the size of each bin based on the total childs and the number of bins.
2) I then adjust this size finding the Top N parents by child where N = number of bins. This is done since I am going to bucket parents by simple order (Parent ID and Child ID). This means I will most likely end up with parents that have children in two buckets which obviously is not desired. My approach is to move these parents to the last bucket hence I have to increase the bucket size. In the worst case scenario I will have the parents with most childs overflowing into the next bucket for all buckets. So I find out which are the Top N parents and then increase my total child universe by that much.
3) I then bucket the data using the WIDTH_BUCKET function and ROW_NUMBER by simple order (Parent ID and Child ID)
4) I then find out the parents that have children in two buckets.
5) And finally I move the "broken" parents to the last bucket.
This approach seems to work well. I ran it for ~130,000 parents 500,000 childs and the query returns the bucketed data in 4 seconds. The number of buckets does not affect the performance of the query.
WITH total_bins AS
     -- Load the number of bins
     SELECT 5 AS BIN_COUNT
       FROM DUAL
count_childs AS
     -- Calculate the sum of child records for top N parents based on the number of bins and the total number of child records
     SELECT SUM(CASE WHEN ranked.RANK <= total_bins.BIN_COUNT THEN ranked.CHILD_COUNT ELSE NULL END) AS TOP_N_CHILDS,
            SUM(CHILD_COUNT) AS TOTAL_CHILDS 
       FROM
               -- Rank records by their child count
               SELECT CHILD_COUNT, ROW_NUMBER() OVER (ORDER BY CHILD_COUNT DESC) AS RANK FROM 
                      -- Count all child records for each parent
                      SELECT PARENT_ID, COUNT(1) AS CHILD_COUNT FROM PARENT_CHILD GROUP BY PARENT_ID ORDER BY 2 DESC
          ) ranked
          CROSS JOIN
          total_bins
bins AS
     -- Calculate each bin's size based on the number of childs and bins
     -- top_n_childs is used to increase the bins in case of childs from 1
     -- parent falling into 2 different bins
     SELECT CEIL((TOTAL_CHILDS + TOP_N_CHILDS) / total_bins.BIN_COUNT) AS SIZE_EACH,
            CEIL((TOTAL_CHILDS + TOP_N_CHILDS) / total_bins.BIN_COUNT) * total_bins.BIN_COUNT AS SIZE_ALL
       FROM count_childs
            CROSS JOIN
            total_bins
bucket_data AS
     -- Bucket data using WIDTH_BUCKET data function, most likely child records will end in 2 buckets
     SELECT PARENT_ID,
            CHILD_ID,
            WIDTH_BUCKET(ORDER_NUMBER, 1, (SELECT bins.SIZE_ALL FROM bins), (SELECT total_bins.BIN_COUNT FROM total_bins)) AS BUCKET
       FROM
            SELECT PARENT_ID, CHILD_ID, ROW_NUMBER() OVER (ORDER BY PARENT_ID, CHILD_ID) ORDER_NUMBER FROM PARENT_CHILD
broken_parents AS
     -- This finds out which parents have their child records on more than 1 bucket so they can be fixed
     SELECT PARENT_ID FROM bucket_data GROUP BY PARENT_ID HAVING COUNT(DISTINCT BUCKET) > 1
fixed_data AS
     -- Join bucket_data and broken_parents and moved broken_parents to the last bucket
     SELECT bucket_data.PARENT_ID,
            bucket_data.CHILD_ID,
            CASE WHEN broken_parents.PARENT_ID IS NOT NULL THEN (SELECT total_bins.BIN_COUNT FROM total_bins) ELSE bucket_data.BUCKET END AS BUCKET
       FROM bucket_data,
            broken_parents
      WHERE bucket_data.PARENT_ID = broken_parents.PARENT_ID (+)
SELECT PARENT_ID,
       CHILD_ID,
       BUCKET
  FROM fixed_data
-- Check number of childs per bucket
-- SELECT BUCKET, COUNT(1) FROM fixed_data GROUP BY BUCKET ORDER BY 1
-- Check all parents have their childs on the same bucket
-- SELECT PARENT_ID FROM fixed_data GROUP BY PARENT_ID HAVING COUNT(DISTINCT BUCKET) > 1

Similar Messages

  • Parent swf call function in Child swf not working

    Hi all,
    I'm having a problem with this and I just can't figure it out
    :( (I've been trying different things and staring at it for hours
    and I'm losing my mind...)
    So I have a Parent swf that loads a Child swf (this goes
    without any problems), but I want the Parent to call a function in
    the child, now this is where it goes wrong...
    The function the Parent has to call is named "lookupcar" and
    needs to give the value "wagen" with it. The problem I think is
    that the Parent wants to call the function but it still needs to
    load (correct me if I'm wrong). Is there a way to check if the
    Child swf is loaded completely before trying to call the function?
    Could you give me an example of this please? Or any other
    suggestions on what goes wrong?
    Code in the Parent
    root.inhoud.createEmptyMovieClip("thetext", "thetext",
    this.getNextHighestDepth());
    root.inhoud.thetext.loadMovie("uitrusting-wagenpark.swf");
    root.inhoud.thetext.lookupcar(wagen);
    Code in the Child
    (the function lookupcar)
    _global.lookupcar = function(carnr:String){
    trace("LOOKUPCAR, with car nr: " + carnr);
    Thanks in advance for all the help.

    Perfect....just to make sure i m taking care of it in a nice practical way....here is how i learned to access a file located in Child (researching other posts)
    is this the way you recommend it?
    (LoaderName.content as MovieClip).functionName(new Event("whatever"))
    and in Child File we have
    function functionName(e:Event)
    i have seen other ways of calling a function in Child Swf , like using EmbedSWF and etc. wanna make sure which one is a better practice. Thanks

  • Except function with parent child hierarchy using mdx query

    HI,
    I need to remove some items using mdx query in parent child hierarchy.
    I tried with below query,it is not removeing ,could you please help me.
    SELECT
    {[Measures].[Amount]} ON
    COLUMNS
     NonEmpty([Account].[Accounts].[Account Level 01],[Measures].[Amount])
    ON ROWS
    FROM (SELECT
    -Descendants({[Account].[Accounts].&[47]},,Leaves)
    } ON COLUMNS
    FROM [Adventure Works])
    indu

    Hi Indu,
    Why do you remove some itmes using
    Descendants function? Generally, we use FILTER function to achieve the requirement.
    WITH SET [CustomAccounts] AS
    FILTER ([Account].[Accounts].[Account Level 01].Members , [Account].[Accounts].CurrentMember.Name<>'Net Income')
    SELECT {[Measures].[Internet Sales Amount]} ON 0
    [CustomAccounts] ON 1
    FROM [Adventure Works]
    WITH SET [CustomAccounts] AS
    FILTER ([Account].[Accounts].[Account Level 01].Members , [Account].[Accounts].CurrentMember.Name='Net Income')
    SET [RemainingAccount] AS
    [Account].[Accounts].[Account Level 01]- [CustomAccounts]
    SELECT {[Measures].[Reseller Sales Amount]} ON 0
    [RemainingAccount] ON 1
    FROM [Adventure Works]
    Results.
    References.
    http://www.databasejournal.com/features/mssql/article.php/3306101/MDX-Essentials-Basic-Set-Functions-The-Filter-Function.htm
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/c0149678-97f2-4066-903f-7f9e9ff09b56/filtering-out-dimension-members-with-mdx?forum=sqlanalysisservices
    Regards,
    Charlie Liao
    If you have any feedback on our support,
    please click here.
    Charlie Liao
    TechNet Community Support

  • Function to get the path using a parent-child relationship

    Hello,
    I have a table which uses parent-child relationship to store the options available. I need a function to give me the full path given the id of a particular option.
    I have two different functions. One of them uses the Oracle built in function and the other uses simple queries with a loop.The code of the functions are given below.
    Now, the problem is with their "performance". The difference in their performance is significant. The function using the Oracle function takes more than 2 hours to run a query whereas the other function takes less than 2 minutes.
    I am having trouble trusting the other function. No matter how many tests I perform on the output of both the functions, it always comes out to be the same.
    Any thoughts to help me understand this ??
    Function 1
    =====================
    FUNCTION Gettree (opt_id IN NUMBER,i_app_id IN NUMBER)
    RETURN VARCHAR2
    IS
    path VARCHAR2(32767);
    application_no NUMBER;
    BEGIN
    SELECT ABC.APP_OPT_ID INTO application_no FROM ABC
    WHERE ABC.APP_ID = i_app_id AND ABC.PARENT_ID IS NULL;
    SELECT LPAD(' ', 2*LEVEL-1)||SYS_CONNECT_BY_PATH(app_opt_name, '=>') "Path" INTO path
    FROM ABC
    WHERE app_opt_id = opt_id
    START WITH parent_id =application_no
    CONNECT BY PRIOR app_opt_id =parent_id;
    path := SUBSTR(path,INSTR(path,'>')+1,LENGTH(path));
    RETURN path;
    END Gettree ;
    Function 2
    ======================
    FUNCTION GetOptPath(opt_id NUMBER,app_id NUMBER)
    RETURN VARCHAR2
    IS
    string VARCHAR2(900);
    opt VARCHAR2(100);
    pid NUMBER(38);
    BEGIN
    SELECT ABC.parent_id,ABC.app_opt_name INTO pid,string FROM ABC WHERE ABC.app_opt_id = opt_id;
    IF pid IS NULL
    THEN
    RETURN 'root';
    ELSIF pid IS NOT NULL
    THEN
    LOOP
    SELECT ABC.app_opt_name,ABC.parent_id INTO opt, pid FROM ABC WHERE ABC.app_opt_id = pid;
    EXIT WHEN pid IS NULL;
    string := opt || '=>'|| string;
    END LOOP;
    RETURN string;
    END IF;
    END;

    Hi,
    user8653480 wrote:
    Hello Frank,
    The parameters taken by gettree & getoptpath are app_opt_id and app_id and both the functions return only one string i.e. the path of that particular option (app_opt_id) starting from its root and not all the descendants of that option/root node of that option.
    So, does that mean that gettree first fetches all the descendants of the root node of the given option and then returns the required one ??Yes. It's a little like the situation where you need to meet with your co-worker Amy, so you send an e-mail to everyone in the department telling them to come to your office, and then, when they arrive, tell everyone except Amy that they can leave.
    >
    And if that is the case, then won't it be better to use the bottom-up approach to fetch the required path just for that particular option ?? 'coz my requirement is that only.. given an option_id get the full path starting from the root.Exactly!
    I have used explain plan also for both the functions.. but since I did not know how to anlayze the output from plan_table so I just compared the value in the fields and they were exactly the same for both the queries.If you'd like help analyzing the plans, post them, as Centinul said.
    I am attaching a sample data with the outputs of both the functions for the reference.
    (tried attaching the file but could not find the option, so pasting the data here)
    App_opt_ID     App_ID     Parent_ID     App_opt_name     "gettree(app_opt_id,app_id)"     "getoptpath(app_opt_id,app_id)"
    1          1     NULL          application          NULL                    root
    2          1     1          module1               module1                    module1
    3          1     1          module2               module2                    module2
    4          1     2          submod1               module1=>submod1          module1=>submod1
    5          1     3          submod1               module2=>submod1          module2=>submod1
    6          1     5          opt1               module2=>submod1=>opt1          module2=>submod1=>opt1
    7          2     NULL          app2               NULL                    root
    8          2     7          scr1               scr1                    scr1
    9          2     8          opt1               scr1=>opt1               scr1=>opt1
    10          2     7          scr2               scr2                    scr2Please help.The best solution is to do a bottom-up query, and write a function like reverse_path (described in my first message) to manipulate the string returned by SYS_CONNECT_BY_PATH. You seem to have all the PL/SQL skills needed for this.
    Another approach is a revised form of gettree, like I posted earlier. Does it do what you want or not?
    If you'd help, then post a little sample data in a form people can actually use, such as CREATE TABLE and INSERT statements. Post a few sets of parameters, and the results you need from each set, given the sample data posted.

  • Calling a function in child window from parent window

    Hi,
    How can I call a method in child window from parent window in adobe air using javascript. In the following example I need to call mytest() function in
    child.html from parent.html file.
    Thanks,
    ASM
    //parent.html
    <HTML><HEAD>
    <script>
    var initOptions = new air.NativeWindowInitOptions();
    initOptions.type = air.NativeWindowType.NORMAL;
    initOptions.systemChrome = air.NativeWindowSystemChrome.STANDARD;
    var bounds = new air.Rectangle(300, 300, 600, 500);
    var html2 = air.HTMLLoader.createRootWindow(false, initOptions, false, bounds);
    var urlReq2 = new air.URLRequest("child.html");
    html2.load(urlReq2);
    html2.stage.nativeWindow.activate();
    html2.window.mytest();       //NOT WORKING
    </script>
    </HEAD><body></body></HTML> 
    // child.html
    <HTML><HEAD>
    <script>
    function mytest()
      air.trace("in child window");
    </script>
    </HEAD> <body></body></HTML>

    I suspect your problem is that the child window hasn't been created by the time you call the function in the parent.Loading the content is an asynchronous processes -- AIR doesn't stop executing your code until the window has finished loading child.html. So, you will need to add an eventlistener to html2 and call the function from there:
    html2.addEventListener( "complete", onChildLoaded );
    function onChildLoaded( event )
         html2.window.mytest();

  • Are analytic functions usefull only for data warehouses?

    Hi,
    I deal with reporting queries on Oracle databases but I don't work on Data Warehouses, thus I'd like to know if learning to use analytic functions (sql for anaylis such as rollup, cube, grouping, ...) might be usefull in helping me to develop better reports or if analytic functions are usually usefull only for data warehouses queries. I mean are rollup, cube, grouping, ... usefull also on operational database or do they make sense only on DWH?
    Thanks!

    Mark1970 wrote:
    thus does it worth learning them for improving report queries also not on DHW but on common operational databases?Why pigeonhole report queries as "+operational+" or "+data warehouse+"?
    Do you tell a user/manager that "<i>No, this report cannot be done as it looks like a data warehouse report and we have an operational database!</i>"?
    Data processing and data reporting requirements not not care what label you assign to your database.
    Simple real world example of using analytical queries on a non warehouse. We supply data to an external system via XML. They require that we limit the number of parent entities per XML file we supply. E.g. 100 customer elements (together with all their child elements) per file. Analytical SQL enables this to be done by creating "buckets" that can only contain 100 parent elements at a time. Complete process is SQL driven - no slow-by-slow row by row processing in PL/SQL using nested cursor loops and silly approaches like that.
    Analytical SQL is a tool in the developer toolbox. It would be unwise to remove it from the toolbox, thinking that it is not applicable and won't be needed for the work that's to be done.

  • Lag analytical function and controlling the offset

    Can you help me on that? Small challenge. At least I gave up in half a day.
    Data
    ACCOUNT_NUMBER     BATCH_ID     TRANSACTION_DATE     TRANSACTION_TYPE     TRANSACTION_NUMBER     PARENT_TRANSACTION_NUMBER
    124680     ZY000489     1/11/2011     62     377     NULL
    124680     ZY000489     1/11/2011     1     378     NULL
    124680     ZY000489     1/11/2011     1     379     NULL
    124680     ZY000489     1/11/2011     1     380     NULL
    124680     ZY000489     1/11/2011     62     381     NULL
    124680     ZY000489     1/11/2011     1     381     NULL
    124681     ZY000490     1/11/2011     350     4000     NULL
    124681     ZY000490     1/11/2011     1     4001     NULL
    124681     ZY000490     1/11/2011     1     4002     NULL
    I want to identify parent Transaction Number for each row in above data.
    The way to identify it is My parent transaction Id is
    -     All child transaction have type as 1
    -     One main transaction can have multiple line items.
    -     Any transaction (type) can have an related child transaction (Transaction Type as 1)
    -     Each logical group of transactions have same account number, batch id, transaction date and consecutive Transaction Number (like 377, 378, 379, 380 in above example)
    The data should look like below once I identified parent transaction columns:
    ACCOUNT_NUMBER     BATCH_ID     TRANSACTION_DATE     TRANSACTION_TYPE     TRANSACTION_NUMBER     PARENT_TRANSACTION_NUMBER
    124680     ZY000489     1/11/2011     62     377     377
    124680     ZY000489     1/11/2011     1     378     377
    124680     ZY000489     1/11/2011     1     379     377
    124680     ZY000489     1/11/2011     1     380     377
    124680     ZY000489     1/11/2011     62     381     381
    124680     ZY000489     1/11/2011     1     382     381
    124681     ZY000490     1/11/2011     350     4000     4000
    124681     ZY000490     1/11/2011     1     4001     4000
    124681     ZY000490     1/11/2011     1     4002     4000
    I tried using LAG Analytical function trying to lag dynamically with offset but had difficulties dynamically expanding the offset. Its an Control Break kind of functionality that i want to achieve in single SQL.
    i Know we can do it using pl/sql construct but the challenge is to do it using single sql. Please help
    Please let me know if you are able to do it in single SQL.
    Thanks

    rohitgoswami wrote:
    Can you help me on that? Small challenge. At least I gave up in half a day.
    Data
    ACCOUNT_NUMBER     BATCH_ID     TRANSACTION_DATE     TRANSACTION_TYPE     TRANSACTION_NUMBER     PARENT_TRANSACTION_NUMBER
    124680     ZY000489     1/11/2011     62     377     NULL
    124680     ZY000489     1/11/2011     1     378     NULL
    124680     ZY000489     1/11/2011     1     379     NULL
    124680     ZY000489     1/11/2011     1     380     NULL
    124680     ZY000489     1/11/2011     62     381     NULL
    124680     ZY000489     1/11/2011     1     381     NULL
    124681     ZY000490     1/11/2011     350     4000     NULL
    124681     ZY000490     1/11/2011     1     4001     NULL
    124681     ZY000490     1/11/2011     1     4002     NULL
    I want to identify parent Transaction Number for each row in above data.
    The way to identify it is My parent transaction Id is
    -     All child transaction have type as 1
    -     One main transaction can have multiple line items.
    -     Any transaction (type) can have an related child transaction (Transaction Type as 1)
    -     Each logical group of transactions have same account number, batch id, transaction date and consecutive Transaction Number (like 377, 378, 379, 380 in above example)
    The data should look like below once I identified parent transaction columns:
    ACCOUNT_NUMBER     BATCH_ID     TRANSACTION_DATE     TRANSACTION_TYPE     TRANSACTION_NUMBER     PARENT_TRANSACTION_NUMBER
    124680     ZY000489     1/11/2011     62     377     377
    124680     ZY000489     1/11/2011     1     378     377
    124680     ZY000489     1/11/2011     1     379     377
    124680     ZY000489     1/11/2011     1     380     377
    124680     ZY000489     1/11/2011     62     381     381
    124680     ZY000489     1/11/2011     1     382     381
    124681     ZY000490     1/11/2011     350     4000     4000
    124681     ZY000490     1/11/2011     1     4001     4000
    124681     ZY000490     1/11/2011     1     4002     4000
    I tried using LAG Analytical function trying to lag dynamically with offset but had difficulties dynamically expanding the offset. Its an Control Break kind of functionality that i want to achieve in single SQL.
    i Know we can do it using pl/sql construct but the challenge is to do it using single sql. Please help
    Please let me know if you are able to do it in single SQL.
    ThanksCan probably pretty this up ... i just went for functional code for the moment.
    TUBBY_TUBBZ?with
      2     data (acc_no, batch_id, trans_date, trans_type, trans_no) as
      3  (
      4    select 124680, 'ZY000489', to_date('1/11/2011', 'mm/dd/yyyy'), 62   , 377   from dual union all
      5    select 124680, 'ZY000489', to_date('1/11/2011', 'mm/dd/yyyy'), 1    , 378   from dual union all
      6    select 124680, 'ZY000489', to_date('1/11/2011', 'mm/dd/yyyy'), 1    , 379   from dual union all
      7    select 124680, 'ZY000489', to_date('1/11/2011', 'mm/dd/yyyy'), 1    , 380   from dual union all
      8    select 124680, 'ZY000489', to_date('1/11/2011', 'mm/dd/yyyy'), 62   , 381   from dual union all
      9    select 124680, 'ZY000489', to_date('1/11/2011', 'mm/dd/yyyy'), 1    , 382   from dual union all
    10    select 124681, 'ZY000490', to_date('1/11/2011', 'mm/dd/yyyy'), 350  , 4000  from dual union all
    11    select 124681, 'ZY000490', to_date('1/11/2011', 'mm/dd/yyyy'), 1    , 4001  from dual union all
    12    select 124681, 'ZY000490', to_date('1/11/2011', 'mm/dd/yyyy'), 1    , 4002  from dual
    13  )
    14  select
    15    acc_no,
    16    batch_id,
    17    trans_date,
    18    trans_type,
    19    trans_no,
    20    case when trans_type != 1
    21    then
    22      trans_no
    23    else
    24      lag
    25      (
    26        case when trans_type = 1
    27        then
    28           null
    29        else
    30           trans_no
    31        end
    32        ignore nulls
    33      ) over (partition by acc_no, batch_id, trans_date order by trans_no asc)
    34    end as parent_trans_no
    35  from data;
                ACC_NO BATCH_ID                 TRANS_DATE                         TRANS_TYPE           TRANS_NO    PARENT_TRANS_NO
                124680 ZY000489                 11-JAN-2011 12 00:00                       62                377                377
                124680 ZY000489                 11-JAN-2011 12 00:00                        1                378                377
                124680 ZY000489                 11-JAN-2011 12 00:00                        1                379                377
                124680 ZY000489                 11-JAN-2011 12 00:00                        1                380                377
                124680 ZY000489                 11-JAN-2011 12 00:00                       62                381                381
                124680 ZY000489                 11-JAN-2011 12 00:00                        1                382                381
                124681 ZY000490                 11-JAN-2011 12 00:00                      350               4000               4000
                124681 ZY000490                 11-JAN-2011 12 00:00                        1               4001               4000
                124681 ZY000490                 11-JAN-2011 12 00:00                        1               4002               4000
    9 rows selected.
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?

  • Getting parent-child data into an Oracle level-based OLAP hierarchy

    We have some organisational data which we need to represent in an Oracle OLAP 10g dimension, preferably populated using Warehouse Builder.
    The organisational hierarchy is listed as parent-child pairs, and is both ragged (unbalanced) and skip-level (noncovering). This would lend itself to a value-based hierarchy, but our client would rather we use ROLAP rather than MOLAP, i.e. avoid the use of an Analytical Workspace, which rules out the use of a value-based hierarchy.
    Is there a straightforward way to populate a level-based hierarchy using parent-child pair data, and if so how can it be done?
    Pointers to tutorials would be welcome, especially if they use Warehouse Builder.

    If you have an Oracle DB have a look on the CONNECT BY PRIOR functionality.
    regards
    John
    http://obiee101.blogspot.com

  • Creating View for a table with parent child relation in table

    I need help creating a view. It is on a base table which is a metadata table.It is usinf parent child relationship. There are four types of objects, Job, Workflow, Dataflow and ABAP dataflow. Job would be the root parent everytime. I have saved all the jobs
    of the project in another table TABLE_JOB with column name JOB_NAME. Query should iteratively start from the job and search all the child nodes and then display all child with the job name. Attached are the images of base table data and expected view data
    and also the excel sheet with data.Picture 1 is the sample data in base table. Picture 2 is data in the view.
    Base Table
    PARENT_OBJ
    PAREBT_OBJ_TYPE
    DESCEN_OBJ
    DESCEN_OBJ_TYPE
    JOB_A
    JOB
    WF_1
    WORKFLOW
    JOB_A
    JOB
    DF_1
    DATAFLOW
    WF_1
    WORKFLOW
    DF_2
    DATAFLOW
    DF_1
    DATAFLOW
    ADF_1
    ADF
    JOB_B
    JOB
    WF_2
    WORKFLOW
    JOB_B
    JOB
    WF_3
    WORKFLOW
    WF_2
    WORKFLOW
    DF_3
    DATAFLOW
    WF_3
    WORKFLOW
    DF_4
    DATAFLOW
    DF_4
    DATAFLOW
    ADF_2
    ADF
    View
    Job_Name
    Flow_Name
    Flow_Type
    Job_A
    WF_1
    WORKFLOW
    Job_A
    DF_1
    DATAFLOW
    Job_A
    DF_2
    DATAFLOW
    Job_A
    ADF_1
    ADF
    Job_B
    WF_2
    WORKFLOW
    Job_B
    WF_3
    WORKFLOW
    Job_B
    DF_3
    DATAFLOW
    Job_B
    DF_4
    DATAFLOW
    Job_B
    ADF_2
    ADF
    I implemented the same in oracle using CONNECT_BY_ROOT and START WITH.
    Regards,
    Megha

    I think what you need is recursive CTE
    Consider your table below
    create table basetable
    (PARENT_OBJ varchar(10),
    PAREBT_OBJ_TYPE varchar(10),
    DESCEN_OBJ varchar(10),DESCEN_OBJ_TYPE varchar(10))
    INSERT basetable(PARENT_OBJ,PAREBT_OBJ_TYPE,DESCEN_OBJ,DESCEN_OBJ_TYPE)
    VALUES('JOB_A','JOB','WF_1','WORKFLOW'),
    ('JOB_A','JOB','DF_1','DATAFLOW'),
    ('WF_1','WORKFLOW','DF_2','DATAFLOW'),
    ('DF_1','DATAFLOW','ADF_1','ADF'),
    ('JOB_B','JOB','WF_2','WORKFLOW'),
    ('JOB_B','JOB','WF_3','WORKFLOW'),
    ('WF_2','WORKFLOW','DF_3','DATAFLOW'),
    ('WF_3','WORKFLOW','DF_4','DATAFLOW'),
    ('DF_4','DATAFLOW','ADF_2','ADF')
    ie first create a UDF like below to get hierarchy recursively
    CREATE FUNCTION GetHierarchy
    @Object varchar(10)
    RETURNS @RESULTS table
    PARENT_OBJ varchar(10),
    DESCEN_OBJ varchar(10),
    DESCEN_OBJ_TYPE varchar(10)
    AS
    BEGIN
    ;With CTE
    AS
    SELECT PARENT_OBJ,DESCEN_OBJ,DESCEN_OBJ_TYPE
    FROM basetable
    WHERE PARENT_OBJ = @Object
    UNION ALL
    SELECT b.PARENT_OBJ,b.DESCEN_OBJ,b.DESCEN_OBJ_TYPE
    FROM CTE c
    JOIN basetable b
    ON b.PARENT_OBJ = c.DESCEN_OBJ
    INSERT @RESULTS
    SELECT @Object,DESCEN_OBJ,DESCEN_OBJ_TYPE
    FROM CTE
    OPTION (MAXRECURSION 0)
    RETURN
    END
    Then you can invoke it as below
    SELECT * FROM dbo.GetHierarchy('JOB_A')
    Now you need to use this for every parent obj (start obj) in view 
    for that create view as below
    CREATE VIEW vw_Table
    AS
    SELECT f.*
    FROM (SELECT DISTINCT PARENT_OBJ FROM basetable r
    WHERE NOT EXISTS (SELECT 1
    FROM basetable WHERE DESCEN_OBJ = r.PARENT_OBJ)
    )b
    CROSS APPLY dbo.GetHierarchy(b.PARENT_OBJ) f
    GO
    This will make sure it will give full hieraracy for each start object
    Now just call view as below and see the output
    SELECT * FROM vw_table
    Output
    PARENT_OBJ DESCEN_OBJ DESCEN_OBJ_TYPE
    JOB_A WF_1 WORKFLOW
    JOB_A DF_1 DATAFLOW
    JOB_A ADF_1 ADF
    JOB_A DF_2 DATAFLOW
    JOB_B WF_2 WORKFLOW
    JOB_B WF_3 WORKFLOW
    JOB_B DF_4 DATAFLOW
    JOB_B ADF_2 ADF
    JOB_B DF_3 DATAFLOW
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Dynamic hierarchy in parent child hierarchy table??

    Do you have any experience to handle the requirement of dynamic hierarchy in universe/webi?
    We have some data in parent child hierarchy as below u201CCustomeru201D table.
    Customer
    Parent          Child
    Z                  A
    Z                  B
    A                  AA
    B                  BB
    AA               AAA
    For example, Company Z is the parent company of Company A.
    Another table, Amount is the amount value of different Customers.
    Amount
    ID               Amt
    AA               10
    AAA            1
    BB                2
    Is there any functionality in Universe designer to build related Classes and objects, So that the web intelligence documents represent the following report with the drilling results?
    When we want to see the ID and Amt, the expected result should be:
    Z                13
    when we drill down Z
    the result should be:
    A                11
    B                2
    when we drill down A:
    the result should be:
    AA              11
    notes **
    the level of hierarchy is dynamic
    Any suggestion is appreciated.  Thanks.

    Hi,
    The only way to do it is to create recursive derived table that flatten you parent child hierarchy with a given maximum depth.
    Here is a sample I built a long time ago to flatten a parent-child hierarchy on Employees table in Foodmart database (SQL Server).
    Didier
    SELECT DISTINCT
         Z.employee_id,
         A.supervisor_id_1,
         A.employee_id_1,
         A.full_name_1,
         A.supervisor_id_2,
         A.employee_id_2,
         A.full_name_2,
         A.supervisor_id_3,
         A.employee_id_3,
         A.full_name_3,
         A.supervisor_id_4,
         A.employee_id_4,
         A.full_name_4,
         A.supervisor_id_5,
         A.employee_id_5,
         A.full_name_5,
         A.supervisor_id_6,
         A.employee_id_6,
         A.full_name_6,
         Z.supervisor_id AS supervisor_id_7,
         Z.employee_id AS employee_id_7,
         Z.full_name AS full_name_7
    FROM employee Z,
         SELECT DISTINCT
              A.supervisor_id_1,
              A.employee_id_1,
              A.full_name_1,
              A.supervisor_id_2,
              A.employee_id_2,
              A.full_name_2,
              A.supervisor_id_3,
              A.employee_id_3,
              A.full_name_3,
              A.supervisor_id_4,
              A.employee_id_4,
              A.full_name_4,
              A.supervisor_id_5,
              A.employee_id_5,
              A.full_name_5,
              Z.supervisor_id AS supervisor_id_6,
              Z.employee_id AS employee_id_6,
              Z.full_name AS full_name_6
         FROM employee Z,
              SELECT DISTINCT
                   A.supervisor_id_1,
                   A.employee_id_1,
                   A.full_name_1,
                   A.supervisor_id_2,
                   A.employee_id_2,
                   A.full_name_2,
                   A.supervisor_id_3,
                   A.employee_id_3,
                   A.full_name_3,
                   A.supervisor_id_4,
                   A.employee_id_4,
                   A.full_name_4,
                   Z.supervisor_id AS supervisor_id_5,
                   Z.employee_id AS employee_id_5,
                   Z.full_name AS full_name_5
              FROM employee Z,
                   SELECT DISTINCT
                        A.supervisor_id_1,
                        A.employee_id_1,
                        A.full_name_1,
                        A.supervisor_id_2,
                        A.employee_id_2,
                        A.full_name_2,
                        A.supervisor_id_3,
                        A.employee_id_3,
                        A.full_name_3,
                        Z.supervisor_id AS supervisor_id_4,
                        Z.employee_id AS employee_id_4,
                        Z.full_name AS full_name_4
                   FROM employee Z,
                        SELECT DISTINCT
                             A.supervisor_id_1,
                             A.employee_id_1,
                             A.full_name_1,
                             A.supervisor_id_2,
                             A.employee_id_2,
                             A.full_name_2,
                             Z.supervisor_id AS supervisor_id_3,
                             Z.employee_id AS employee_id_3,
                             Z.full_name AS full_name_3
                        FROM employee Z,
                             SELECT DISTINCT
                                  A.supervisor_id_1,
                                  A.employee_id_1,
                                  A.full_name_1,
                                  Z.supervisor_id AS supervisor_id_2,
                                  Z.employee_id AS employee_id_2,
                                  Z.full_name AS full_name_2
                             FROM employee Z,
                                  SELECT DISTINCT
                                       supervisor_id AS supervisor_id_1,
                                       employee_id AS employee_id_1,
                                       full_name AS full_name_1
                                   FROM employee
                                   WHERE supervisor_id = 0 OR supervisor_id IS NULL
                             ) A
                             WHERE A.employee_id_1 = Z.supervisor_id
                        ) A
                        WHERE A.employee_id_2 = Z.supervisor_id
                   ) A
                   WHERE A.employee_id_3 = Z.supervisor_id
              ) A
              WHERE A.employee_id_4 = Z.supervisor_id
         ) A
         WHERE A.employee_id_5 = Z.supervisor_id
    ) A
    WHERE A.employee_id_6 = Z.supervisor_id
    UNION
    SELECT DISTINCT
         A.employee_id_6 AS employee_id,
         A.supervisor_id_1,
         A.employee_id_1,
         A.full_name_1,
         A.supervisor_id_2,
         A.employee_id_2,
         A.full_name_2,
         A.supervisor_id_3,
         A.employee_id_3,
         A.full_name_3,
         A.supervisor_id_4,
         A.employee_id_4,
         A.full_name_4,
         A.supervisor_id_5,
         A.employee_id_5,
         A.full_name_5,
         A.supervisor_id_6,
         A.employee_id_6,
         A.full_name_6,
         NULL AS supervisor_id_7,
         NULL AS employee_id_7,
         NULL AS full_name_7
    FROM employee Z,
         SELECT DISTINCT
              A.supervisor_id_1,
              A.employee_id_1,
              A.full_name_1,
              A.supervisor_id_2,
              A.employee_id_2,
              A.full_name_2,
              A.supervisor_id_3,
              A.employee_id_3,
              A.full_name_3,
              A.supervisor_id_4,
              A.employee_id_4,
              A.full_name_4,
              A.supervisor_id_5,
              A.employee_id_5,
              A.full_name_5,
              Z.supervisor_id AS supervisor_id_6,
              Z.employee_id AS employee_id_6,
              Z.full_name AS full_name_6
         FROM employee Z,
              SELECT DISTINCT
                   A.supervisor_id_1,
                   A.employee_id_1,
                   A.full_name_1,
                   A.supervisor_id_2,
                   A.employee_id_2,
                   A.full_name_2,
                   A.supervisor_id_3,
                   A.employee_id_3,
                   A.full_name_3,
                   A.supervisor_id_4,
                   A.employee_id_4,
                   A.full_name_4,
                   Z.supervisor_id AS supervisor_id_5,
                   Z.employee_id AS employee_id_5,
                   Z.full_name AS full_name_5
              FROM employee Z,
                   SELECT DISTINCT
                        A.supervisor_id_1,
                        A.employee_id_1,
                        A.full_name_1,
                        A.supervisor_id_2,
                        A.employee_id_2,
                        A.full_name_2,
                        A.supervisor_id_3,
                        A.employee_id_3,
                        A.full_name_3,
                        Z.supervisor_id AS supervisor_id_4,
                        Z.employee_id AS employee_id_4,
                        Z.full_name AS full_name_4
                   FROM employee Z,
                        SELECT DISTINCT
                             A.supervisor_id_1,
                             A.employee_id_1,
                             A.full_name_1,
                             A.supervisor_id_2,
                             A.employee_id_2,
                             A.full_name_2,
                             Z.supervisor_id AS supervisor_id_3,
                             Z.employee_id AS employee_id_3,
                             Z.full_name AS full_name_3
                        FROM employee Z,
                             SELECT DISTINCT
                                  A.supervisor_id_1,
                                  A.employee_id_1,
                                  A.full_name_1,
                                  Z.supervisor_id AS supervisor_id_2,
                                  Z.employee_id AS employee_id_2,
                                  Z.full_name AS full_name_2
                             FROM employee Z,
                                  SELECT DISTINCT
                                       supervisor_id AS supervisor_id_1,
                                       employee_id AS employee_id_1,
                                       full_name AS full_name_1
                                   FROM employee
                                   WHERE supervisor_id = 0 OR supervisor_id IS NULL
                             ) A
                             WHERE A.employee_id_1 = Z.supervisor_id
                        ) A
                        WHERE A.employee_id_2 = Z.supervisor_id
                   ) A
                   WHERE A.employee_id_3 = Z.supervisor_id
              ) A
              WHERE A.employee_id_4 = Z.supervisor_id
         ) A
         WHERE A.employee_id_5 = Z.supervisor_id
    ) A
    UNION
    SELECT DISTINCT
         A.employee_id_5 AS employee_id,
         A.supervisor_id_1,
         A.employee_id_1,
         A.full_name_1,
         A.supervisor_id_2,
         A.employee_id_2,
         A.full_name_2,
         A.supervisor_id_3,
         A.employee_id_3,
         A.full_name_3,
         A.supervisor_id_4,
         A.employee_id_4,
         A.full_name_4,
         A.supervisor_id_5,
         A.employee_id_5,
         A.full_name_5,
         NULL AS supervisor_id_6,
         NULL AS employee_id_6,
         NULL AS full_name_6,
         NULL AS supervisor_id_7,
         NULL AS employee_id_7,
         NULL AS full_name_7
    FROM employee Z,
         SELECT DISTINCT
              A.supervisor_id_1,
              A.employee_id_1,
              A.full_name_1,
              A.supervisor_id_2,
              A.employee_id_2,
              A.full_name_2,
              A.supervisor_id_3,
              A.employee_id_3,
              A.full_name_3,
              A.supervisor_id_4,
              A.employee_id_4,
              A.full_name_4,
              Z.supervisor_id AS supervisor_id_5,
              Z.employee_id AS employee_id_5,
              Z.full_name AS full_name_5
         FROM employee Z,
              SELECT DISTINCT
                   A.supervisor_id_1,
                   A.employee_id_1,
                   A.full_name_1,
                   A.supervisor_id_2,
                   A.employee_id_2,
                   A.full_name_2,
                   A.supervisor_id_3,
                   A.employee_id_3,
                   A.full_name_3,
                   Z.supervisor_id AS supervisor_id_4,
                   Z.employee_id AS employee_id_4,
                   Z.full_name AS full_name_4
              FROM employee Z,
                   SELECT DISTINCT
                        A.supervisor_id_1,
                        A.employee_id_1,
                        A.full_name_1,
                        A.supervisor_id_2,
                        A.employee_id_2,
                        A.full_name_2,
                        Z.supervisor_id AS supervisor_id_3,
                        Z.employee_id AS employee_id_3,
                        Z.full_name AS full_name_3
                   FROM employee Z,
                        SELECT DISTINCT
                             A.supervisor_id_1,
                             A.employee_id_1,
                             A.full_name_1,
                             Z.supervisor_id AS supervisor_id_2,
                             Z.employee_id AS employee_id_2,
                             Z.full_name AS full_name_2
                        FROM employee Z,
                             SELECT DISTINCT
                                  supervisor_id AS supervisor_id_1,
                                  employee_id AS employee_id_1,
                                  full_name AS full_name_1
                              FROM employee
                              WHERE supervisor_id = 0 OR supervisor_id IS NULL
                        ) A
                        WHERE A.employee_id_1 = Z.supervisor_id
                   ) A
                   WHERE A.employee_id_2 = Z.supervisor_id
              ) A
              WHERE A.employee_id_3 = Z.supervisor_id
         ) A
         WHERE A.employee_id_4 = Z.supervisor_id
    ) A
    UNION
    SELECT DISTINCT
         A.employee_id_4 AS employee_id,
         A.supervisor_id_1,
         A.employee_id_1,
         A.full_name_1,
         A.supervisor_id_2,
         A.employee_id_2,
         A.full_name_2,
         A.supervisor_id_3,
         A.employee_id_3,
         A.full_name_3,
         A.supervisor_id_4,
         A.employee_id_4,
         A.full_name_4,
         NULL AS supervisor_id_5,
         NULL AS employee_id_5,
         NULL AS full_name_5,
         NULL AS supervisor_id_6,
         NULL AS employee_id_6,
         NULL AS full_name_6,
         NULL AS supervisor_id_7,
         NULL AS employee_id_7,
         NULL AS full_name_7
    FROM employee Z,
         SELECT DISTINCT
              A.supervisor_id_1,
              A.employee_id_1,
              A.full_name_1,
              A.supervisor_id_2,
              A.employee_id_2,
              A.full_name_2,
              A.supervisor_id_3,
              A.employee_id_3,
              A.full_name_3,
              Z.supervisor_id AS supervisor_id_4,
              Z.employee_id AS employee_id_4,
              Z.full_name AS full_name_4
         FROM employee Z,
              SELECT DISTINCT
                   A.supervisor_id_1,
                   A.employee_id_1,
                   A.full_name_1,
                   A.supervisor_id_2,
                   A.employee_id_2,
                   A.full_name_2,
                   Z.supervisor_id AS supervisor_id_3,
                   Z.employee_id AS employee_id_3,
                   Z.full_name AS full_name_3
              FROM employee Z,
                   SELECT DISTINCT
                        A.supervisor_id_1,
                        A.employee_id_1,
                        A.full_name_1,
                        Z.supervisor_id AS supervisor_id_2,
                        Z.employee_id AS employee_id_2,
                        Z.full_name AS full_name_2
                   FROM employee Z,
                        SELECT DISTINCT
                             supervisor_id AS supervisor_id_1,
                             employee_id AS employee_id_1,
                             full_name AS full_name_1
                         FROM employee
                         WHERE supervisor_id = 0 OR supervisor_id IS NULL
                   ) A
                   WHERE A.employee_id_1 = Z.supervisor_id
              ) A
              WHERE A.employee_id_2 = Z.supervisor_id
         ) A
         WHERE A.employee_id_3 = Z.supervisor_id
    ) A
    UNION
    SELECT DISTINCT
         A.employee_id_3 AS employee_id,
         A.supervisor_id_1,
         A.employee_id_1,
         A.full_name_1,
         A.supervisor_id_2,
         A.employee_id_2,
         A.full_name_2,
         A.supervisor_id_3,
         A.employee_id_3,
         A.full_name_3,
         NULL AS supervisor_id_4,
         NULL AS employee_id_4,
         NULL AS full_name_4,
         NULL AS supervisor_id_5,
         NULL AS employee_id_5,
         NULL AS full_name_5,
         NULL AS supervisor_id_6,
         NULL AS employee_id_6,
         NULL AS full_name_6,
         NULL AS supervisor_id_7,
         NULL AS employee_id_7,
         NULL AS full_name_7
    FROM employee Z,
         SELECT DISTINCT
              A.supervisor_id_1,
              A.employee_id_1,
              A.full_name_1,
              A.supervisor_id_2,
              A.employee_id_2,
              A.full_name_2,
              Z.supervisor_id AS supervisor_id_3,
              Z.employee_id AS employee_id_3,
              Z.full_name AS full_name_3
         FROM employee Z,
              SELECT DISTINCT
                   A.supervisor_id_1,
                   A.employee_id_1,
                   A.full_name_1,
                   Z.supervisor_id AS supervisor_id_2,
                   Z.employee_id AS employee_id_2,
                   Z.full_name AS full_name_2
              FROM employee Z,
                   SELECT DISTINCT
                        supervisor_id AS supervisor_id_1,
                        employee_id AS employee_id_1,
                        full_name AS full_name_1
                    FROM employee
                    WHERE supervisor_id = 0 OR supervisor_id IS NULL
              ) A
              WHERE A.employee_id_1 = Z.supervisor_id
         ) A
         WHERE A.employee_id_2 = Z.supervisor_id
    ) A
    UNION
    SELECT DISTINCT
         A.employee_id_2 AS employee_id,
         A.supervisor_id_1,
         A.employee_id_1,
         A.full_name_1,
         A.supervisor_id_2,
         A.employee_id_2,
         A.full_name_2,
         NULL AS supervisor_id_3,
         NULL AS employee_id_3,
         NULL AS full_name_3,
         NULL AS supervisor_id_4,
         NULL AS employee_id_4,
         NULL AS full_name_4,
         NULL AS supervisor_id_5,
         NULL AS employee_id_5,
         NULL AS full_name_5,
         NULL AS supervisor_id_6,
         NULL AS employee_id_6,
         NULL AS full_name_6,
         NULL AS supervisor_id_7,
         NULL AS employee_id_7,
         NULL AS full_name_7
    FROM employee Z,
         SELECT DISTINCT
              A.supervisor_id_1,
              A.employee_id_1,
              A.full_name_1,
              Z.supervisor_id AS supervisor_id_2,
              Z.employee_id AS employee_id_2,
              Z.full_name AS full_name_2
         FROM employee Z,
              SELECT DISTINCT
                   supervisor_id AS supervisor_id_1,
                   employee_id AS employee_id_1,
                   full_name AS full_name_1
               FROM employee
               WHERE supervisor_id = 0 OR supervisor_id IS NULL
         ) A
         WHERE A.employee_id_1 = Z.supervisor_id
    ) A
    UNION
    SELECT DISTINCT
         A.employee_id_1 AS employee_id,
         A.supervisor_id_1,
         A.employee_id_1,
         A.full_name_1,
         NULL AS supervisor_id_2,
         NULL AS employee_id_2,
         NULL AS full_name_2,
         NULL AS supervisor_id_3,
         NULL AS employee_id_3,
         NULL AS full_name_3,
         NULL AS supervisor_id_4,
         NULL AS employee_id_4,
         NULL AS full_name_4,
         NULL AS supervisor_id_5,
         NULL AS employee_id_5,
         NULL AS full_name_5,
         NULL AS supervisor_id_6,
         NULL AS employee_id_6,
         NULL AS full_name_6,
         NULL AS supervisor_id_7,
         NULL AS employee_id_7,
         NULL AS full_name_7
    FROM employee Z,
         SELECT DISTINCT
              supervisor_id AS supervisor_id_1,
              employee_id AS employee_id_1,
              full_name AS full_name_1
          FROM employee
          WHERE supervisor_id = 0 OR supervisor_id IS NULL
    ) A

  • Parent-Child relation total

    i have 2 tables;
    Table 1
    Parent ID
    Parent Name
    Amount
    table 2
    DPND_CODE             
    DPND_NAME             
    DPND_RELAT_CODE       
    DPND_DOB              
    DPND_YN               
    DPND_SHARE_AMOUNT     
    DPND_BANK_CODE        
    DPND_BANK_AC_NO       
    DPND_AGENT_CODE       
    the query should check for the WHERE condition that dpnd_yn "Y"
    Parent ID       Parent Name        Amount
    001                emp1                   200.000
        001_01       emp1_chld1     50.000
        001_02       emp1_chld2     50.000
        001_03       emp1_chld3     50.000
        001_04       emp1_chld4     50.000
    .

    i was totally confused n hasty..Sorry to post with so incomplete info.
    actually i have a table that stores the total amount paid to an employee.
    for that my Table1 above serves the purpose.
    Table 1
    Parent ID
    Parent Name
    Amount
    the IInd table stores the distribution of the above (TABLE 1) total amount,
    to his family in case he has died. so the correct child table 2 struc is;
    table 2
    DPND_CODE             
    DPND_NAME             
    DPND_RELAT_CODE       
    DPND_DOB              
    DPND_YN               
    DPND_SHARE_AMOUNT     
    DPND_BANK_CODE        
    DPND_BANK_AC_NO       
    DPND_AGENT_CODE
    dpnd_PARENT_id  (Foreign key)
    and therefore the result that m looking for is;
    PARENT ID      PARENT NAME      AMOUNT
    001                emp1                   200.000 <------FROM TABLE 1
        dpnd_code  dpnd_name     dpnd_share_amount
        001_01       emp1_chld1     50.000  |
        001_02       emp1_chld2     50.000  |__FROM TABLE 2
        001_03       emp1_chld3     50.000  |
        001_04       emp1_chld4     50.000  |
    a condition should check whether dpnd_YN field = "Y",
    as all the next-of-kin members details of the deceased family is entered in the system at the time of his death.
    where as per rule only few qualify to get the share from the deceased pension as per policy.
    therefore the query should pick up only child records whom dpnd_YN IS MARKED As 'Y'.
    You've provided (3), but I don't know if that's really a good illustration of your problem.
    Do you have just one root (001), or can you have multiple roots (001, 002, 003, etc.)?
    Does the parent-child relationship go beyond two levels? (Thta is, can you have 001_01_01 or 001_01_02_03?)
    Yes the ROOT is always one, it will never go beyond two levels. (Just 001_01, 001_02...002_01, 002_02...003_01, 003_02..)
    Hope i am much better than before.
    ty
    Edited by: user613563 on Oct 27, 2008 3:01 PM
    Edited by: user613563 on Oct 27, 2008 3:05 PM

  • Parent - child tables foreign key relation ship

    Hi All,
    we have 600 hundred tables ..i would like to print a hierarchial tree based on the foreigh key relathionship
    i tried my best but i couldnt.
    parent table
    child table 1
    childtable3
    child table 2
    and so
    Can somebody help me out with a query?
    Thanks,
    kt

    CREATE OR REPLACE FUNCTION get_child_tables (
    ptable VARCHAR2,
    powner VARCHAR2 DEFAULT 'SCOTT',
    plevel NUMBER DEFAULT 10
    RETURN stringarray
    -- -- create this ON SQL*PLUS "CREATE OR REPLACE TYPE STRINGARRAY AS TABLE OF VARCHAR2(50);"
    -- AUTHID CURRENT_USER
    PIPELINED
    AUTHOR DATE VERSION COMMENTS
    ======================================================================================
    [email protected] 26-OCT-2009 1.0 Developed to ease developers effort to find Nth level of Referential integrity
    ======================================================================================
    -- PURPOSE -> To find PARENT=> CHILD relational TABLE(S) in Oracle upto a depth max N Level.
    --SYNTAX TO USE
    SELECT * FROM TABLE( get_child_tables('DEPT','SCOTT',3)); Store this query in a file for your use
    SELECT * FROM TABLE( get_child_tables('EMPLOYEE')); Store this query in a file for your use
    -- RESULTS looks as below
    --1 => DEPT
    --2 => EMP
    --2 => EMP2
    --3 => EMP_CHILD
    --3 => EMP2_CHILD
    -- and so on
    --This can be leveraged to use in any oracle database REGION 10g having and above.
    --This FUNCTION gives formatted result of the Oracle 10g Hierarchical query result coded in the cursor
    --to find MASTER => CHILD relational TABLE(S) upto a depth max 10 Level.
    --The result of the PIPELINED function can be retrieved using Oracle new operator
    --TABLE(array name) in SQL query.
    --Due to the AUTHID CURRENT_USER compiler directive any user can use based on his/her access privileges on the database.
    --GRANT EXECUTE ON SCOTT.get_child_tables TO PUBLIC;
    --CREATE OR REPLACE PUBLIC SYNONYM get_child_tables FOR SCOTT.get_child_tables;
    IS
    atname stringarray := stringarray ();
    -- create this ON SQL*PLUS CREATE OR REPLACE TYPE STRINGARRAY AS TABLE OF VARCHAR2(50);
    vlevel NUMBER;
    vtname VARCHAR2 (50);
    nindex NUMBER := 0;
    bprocessed BOOLEAN := FALSE;
    CURSOR c1 (powner_in IN VARCHAR2, ptable_in VARCHAR2, plevel_in NUMBER)
    IS
    SELECT LEVEL, LPAD (' ', (LEVEL - 1) * 2, ' ') || pt AS "TNAME"
    FROM (SELECT a.owner w1, a.table_name pt, a.constraint_name c1,
    a.r_constraint_name r1, b.owner w2, b.table_name ct,
    b.constraint_name c2, b.r_constraint_name r2
    FROM all_constraints a, all_constraints b
    WHERE a.constraint_name = b.r_constraint_name(+)
    AND a.owner = b.owner(+)
    AND a.owner =
    UPPER (powner)
    -- Change Owner here while testing
    --AND A.r_constraint_name IS NULL
    AND a.constraint_type IN ('P', 'R')) v1
    START WITH pt =
    UPPER
    (ptable)
    -- Change your master table here while testing the QUERY
    CONNECT BY PRIOR ct = pt AND LEVEL <= plevel;
    -- Change lavel here while testing
    BEGIN
    atname.EXTEND;
    atname (1) := 'NOTHING';
    OPEN c1 (powner, ptable, plevel);
    LOOP
    bprocessed := FALSE;
    FETCH c1
    INTO vlevel, vtname;
    IF nindex > 1 AND atname (atname.LAST - 1) = vtname
    THEN
    --DBMS_OUTPUT.PUT_LINE('2 ==== vtname  ' ||vtname || '   '|| atname.count|| '   '||atname.last ||  '   '||atname( atname.last-1));
    bprocessed := TRUE;
    END IF;
    IF NOT bprocessed
    THEN
    nindex := nindex + 1;
    atname.EXTEND;
    atname (nindex) := vtname;
    PIPE ROW (vlevel || ' => ' || vtname);
    DBMS_OUTPUT.put_line ( ' **** nindex - atname( nindex) '
    || nindex
    || ' - '
    || atname (nindex)
    DLOG('ADDING ',vTname); A LOGGING ATONOMUS PROCEDURE FOR DEBUG PURPOSE
    END IF;
    EXIT WHEN c1%NOTFOUND;
    END LOOP;
    CLOSE c1;
    FOR i IN 1 .. atname.COUNT
    LOOP
    DBMS_OUTPUT.PUT_LINE('atname (i) ' ||atname (i));
    END LOOP;
    RETURN;
    EXCEPTION
    WHEN no_data_needed
    THEN -- THIS EXCEPTION HAS TO BE THERE TO GET THE FUCTION WORKABLE
    DBMS_OUTPUT.put_line (SQLERRM);
    RETURN;
    END get_child_tables;
    /

  • Error with Parent-Child Hierarchies in BIEE11.1.1.5

    Hi ,
    I am using BIEE11.1.1.5, I have created a Logical Dimensions with Parent-Child Hierarchies,
    In answer,I draged the Hierarchies named 'H5 Sales Rep', then view the results,
    It has error,error message as follows:
    Odbc driver returned an error (SQLExecDirectW).
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 43119] Query Failed: [nQSError: 22056] To use hierarchical functions, you need to associate a Closure Table with Logical Table Source 'LTS1 Sales Rep'. (HY000)
    SQL Issued: SELECT 0 s_0, "Sample Sales"."Sales Rep"."Sales Rep Name" s_1, CASE WHEN ISLEAF("Sample Sales"."Sales Rep"."H5 Sales Rep") THEN 1 ELSE 0 END s_2, IDOF("Sample Sales"."Sales Rep"."H5 Sales Rep") s_3, PARENT("Sample Sales"."Sales Rep"."H5 Sales Rep") s_4 FROM "Sample Sales" WHERE ISROOT("Sample Sales"."Sales Rep"."H5 Sales Rep")
    anyone know why???
    Thank you!

    Hi Leo,
    Did you configure closure table? http://www.rittmanmead.com/2010/11/oracle-bi-ee-11g-parent-child-hierarchies-multiple-modeling-methods/
    Also make sure to perform the hierarchy changes in offline mode.
    Regards,
    Dpka

  • Parent Child Hierarchy

    I am new learner for using OBIEE 11g, when I try to create the Parent_Child_Hierarchy in the repository, BI answer in the web shows the errors:
    "State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 38107] *Not all four columns are defined for closure table 'Parent_Chile_Table_Closure'*. (HY000)".
    According to the help web "http://www.adivaconsulting.com/adiva-blog/item/22-obiee-11g-hierarchical-table.html", I have created the relational Parent-Child-Hierarchy table in the database that is imported into the physical layer, and finish every steps, but when I drag the hierarchy in the presentation layer into display scope, which shows the errors mentioned above.
    If you known the method for solving it,please help me and share your idea, thanks!

    Hey,
    I am also facing the same issue when i try to replicate this practice. (Create Logical Dimensions with Parent Child Hierarchies -- http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/bi/bi11115/biadmin11g_02/biadmin11g.htm#t9s3)
    Odbc driver returned an error (SQLExecDirectW).
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 43119] Query Failed: [nQSError: 22056] To use hierarchical functions, you need to associate a Closure Table with Logical Table Source 'LTS1 Sales Rep'. (HY000)
    SQL Issued: SET VARIABLE PREFERRED_CURRENCY='USD';SELECT 0 s_0, "Y - Sample Sales"."Sales Reps"."Sales Rep Name" s_1, CASE WHEN ISLEAF("Y - Sample Sales"."Sales Reps"."H5 Sales Rep DimHier") THEN 1 ELSE 0 END s_2, IDOF("Y - Sample Sales"."Sales Reps"."H5 Sales Rep DimHier") s_3, PARENT("Y - Sample Sales"."Sales Reps"."H5 Sales Rep DimHier") s_4 FROM "Y - Sample Sales" WHERE ISROOT("Y - Sample Sales"."Sales Reps"."H5 Sales Rep DimHier")

  • Parent-child hierarcy - row level security

    Hi,
    Im using OBI 11.1.1.5 and have a problem about row-level security in parent-child dimension.
    I have created a parent-child dimension, simlar to:
    a1
    --a1.1
    ----a1.1.1
    ----a1.1.2
    --a1.2
    ----a1.2.1
    By using a session variable 'SESVAR1', I want to restrict the visible hierarcy. For instance user 'a1.1' should only see:
    a1.1
    --a1.1.1
    --a1.1.2
    To do this I created a parent-child closure table with the whole dataset. Then I created a physical table using select statement with my session variable in repository. Whenever I viewed data in repository, it showed the correct set.
    I created a parent-child dimension, using the original parent-child closure table. But since current distance values are different from the original hierarcy, I can not managed to build a security such a security system with this method.
    How can I build a security system, that a member can only see its child hierarchy only?
    Thanks for answers and links...
    Edited by: user4516917 on 16.Nis.2012 06:54
    Edited by: user4516917 on 16.Nis.2012 06:55

    According to searches I made in support.oracle and google, it seems that it is not possible to view just a branch of a parent-child tree. Because the closure table is static. Therefore, you can not change the distances of objects dynamically.
    This parent-child ability is very frustrating for me. As I understand, parent-child dimension ability can only be used in read-only sources. Any filtering or dynamic changes does not seem possible in this structure. Any changes on parent-child table requires parent-child relation table to be rebuilt.
    I couldnt find any functionality of indexcol or choose functions in parent-child dimensions. I think they can only be used in level based dimensions.
    Any comments appriciated..

Maybe you are looking for