Getting the sum of all members in a hierarchy....

Hi,
I want to get the sum of each member in a hierarchy....
The hierarchy is defined in the table strdet:
create table strdet
(costcenterms varchar2(20),     // parent
costcenterdet varchar2(20),    // child
lev varchar2(1))The values for each object/material per costcenter(child) is defined in the table details_det:
create table details_det
(costcenterms varchar2(20),
eppid varchar2(30) ,
purchcontyear0 number(4,1) )Some sample data:
insert into strdet values ('1' , '1.1','2')
insert into strdet values ('1' , '1.2','2')
insert into strdet values ('1.1' , '1.1.1','3')
insert into strdet values ('1.1' , '1.1.2','3')
insert into strdet values ('1.2' , '1.2.1','3')
insert into strdet values ('1.2' , '1.2.2','3')
insert into strdet values ('1.2' , '1.2.3','3')
insert into strdet values ('1.1.1' , '1.1.1.1','4')
insert into strdet values ('1.1.1' , '1.1.1.2','4')
insert into strdet values ('1.1.2' , '1.1.2.1','4')
insert into strdet values ('1.2.1' , '1.2.1.1','4')
insert into strdet values ('1.2.1' , '1.2.1.2','4')
COMMIT;
insert into details_det values('1.1.1.1','epp1',10);
insert into details_det values('1.1.1.1','epp2',20);
insert into details_det values('1.1.1.1','epp3',0);
insert into details_det values('1.1.1.2','epp1',0);
insert into details_det values('1.1.2.1','epp2',5);
insert into details_det values('1.1.2.1','epp4',15);
insert into details_det values('1.2.1.1','epp1',65);
insert into details_det values('1.2.1.1','epp2',95);
insert into details_det values('1.2.1.2','epp1',5);
commit;The output of the desired sql stmt must be like this:
costcenter             val
1                        220
1.1                       55
1.2                     165
1.1.1                    30
1.1.2                    20
1.2.1                  165I have written the following , so far.....
SQL> select distinct s.costcenterms , sum(purchcontyear0) over(partition by s.costcenterms order by s.costcenterms)
  2        from details_det d , strdet s
  3        where s.costcenterdet=d.costcenterms(+)
  4        start with s.costcenterms='1'
  5             connect by  s.costcenterms = prior s.costcenterdet
  6        order by s.costcenterms
  7  /
COSTCENTERMS                                                 SUM(PURCHCONTYEAR0)OVER(PARTIT
1.2                                                         
1.2.1                                                                                   165
1.1.1                                                                                    30
1.1.2                                                                                    20
1                                                           
1.1                                                         
6 rows selectedHow should i modify the above sql stmt to get the desired result...????
Note: I use OracleDB 10g. v.2
Thanks, a lot
Sim

I' m grateful to all.....!!!!
I connected as user SYS so as to give the appropriate privileges to SCOTT schema ....
SQL*Plus: Release 10.2.0.1.0 - Production on Êõñ Óåð 14 11:03:44 2008
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
SQL> connect sys/***@info as sysdba;
Connected
SQL> grant create materialized view to scott;
Grant succedded
SQL> grant alter any materialized view to scott with admin option;
Grant succedded
SQL> connect scott/tiger@info;
Connected
SQL> create materialized view mv 
  2  as
  3  select s.costcenterms , sum(connect_by_root d.purchcontyear0) sum_cbr
  4   from details_det d  , strdet s
  5   where s.costcenterdet = d.costcenterms(+)
  6  connect by s.costcenterdet = prior s.costcenterms
  7  group by s.costcenterms
  8  order by length(s.costcenterms) , s.costcenterms ;
create materialized view mv
Error in line 1
ORA-30361: unrecognized string type
SQL> create materialized view x_mv
  2  as
  3  select grp, sum(purchcontyear0)
  4  from (
  5  select connect_by_root s.costcenterms grp, d.purchcontyear0
  6   from strdet s, details_det d
  7  where s.costcenterdet=d.costcenterms(+)
  8  connect by s.costcenterms = prior s.costcenterdet
  9  )
10  group by grp
11  /
Materialized view created
SQL> create materialized view mv 
  2  as
  3  select s.costcenterms , sum(connect_by_root d.purchcontyear0) sum_cbr
  4   from details_det d  , strdet s
  5   where s.costcenterdet = d.costcenterms(+)
  6  connect by s.costcenterdet = prior s.costcenterms
  7  group by s.costcenterms ;
create materialized view mv
Error in line 1
ORA-30361: unrecognized string typeTo sum up.....
Rob's version of definition of mv is unsuccessful... even when i omit the order by clause.... whereas SY's version is successful..... Can you imagine why since... as Rob posted above , it is successful in his environment......!!!!!
Note: As regards the ORA- error , the cause and action of Oracle is as follows:
Cause: An internal Oracle error occured.
    Action: Report the problem through your normal support channels. Thanks again,
Sim

Similar Messages

  • Is it possible to get the sum of all true (checked) columns?

    I am totally new to numbers, and I have just a vague understanding of excel, so I be needing some help.
    I am a hairstylist and I am using my iPad for client tracking.  My spreadsheet has totals referring to amount of clients, service totals, retail totals, average service tickets, etc.  I also need to track my pre-booking.  An easy way for me to track my pre's is to have a true/false check box column.  Is there a way to add up all of the true checks?  I have other factors I need to track like amount of services so I would like to utilize the true/false check boxes.  I do not want to add the adjoining columns, just the true false columns.  To clarify, I want to add all of the true check boxes with a resulting sum, of only the true (checked) boxes.
    Hopefully I'm not being mega confusing....

    Yes it is
    Use the COUNTIF function

  • I have my own icloud account separate from my family's apple ID for itunes. I need more storage for icloud...do I have to pay a separate $20/ month to get more storage or does the $20 include all members of the plan?

    I have my own icloud account separate from my family's apple ID for itunes. I need more storage for icloud...do I have to pay a separate $20/ month to get more storage or does the $20 include all members of the plan?

    Welcome to Apple Support Communities
    If your iCloud account uses your family's Apple ID, you will pay $20/year for all your family members. If your iCloud account uses a different Apple ID than your family's Apple ID, you will pay only for you

  • How to get the number of community members from outside the community

    Hi everyone.
    I need to know if there is any way to get the number of community members from outside the community, I mean, not using the "What's happening" webpart. I want to build up a page with a Webpart that summarize my three most visited communities indicating
    number of members, three last messages in the newsfeed, and number of posts in blog, wikis, document libraries, etc.
    Do I need statistics to get this kind of information? Should I use Sharepoint Object model instead?
    Here is an example of what I need:
    - Community name
    - Number of members
    - Community activity (messages, docs uploaded to library, etc)
    - Number of posts in calendar, blog, wiki that belongs to community
    Thank you all!

    Hi Thuan.
    Thanks for your answer but it does not help me because these communities are Sharepoint Communities not external sites so I need to get that information using SP object model and BCS in this case is useless.
    EDIT
    I found the solution using the search objects but I was only able to get members, discussions and replies
    using (ClientContext clientContext = new ClientContext("URL_OF_ENTERPRISE_SEARCH_CENTER"))
    KeywordQuery keywordQuery = new KeywordQuery(clientContext);
    keywordQuery.QueryText = "The_Name_of_the_Community WebTemplate:COMMUNITY";
    SearchExecutor searchExecutor = new SearchExecutor(clientContext);
    ClientResult<ResultTableCollection> results = searchExecutor.ExecuteQuery(keywordQuery);
    clientContext.ExecuteQuery();
    System.Collections.Generic.IDictionary<string, object> ret = null;
    foreach (System.Collections.Generic.Dictionary<string, object> resultRow in results.Value[0].ResultRows)
    Console.WriteLine("{0}: {1} ({2})", resultRow["CommunityMembersCount"], resultRow["CommunityTopicsCount"], resultRow["CommunitiyRepliesCount"]);
    This is a Console Application.
    I hope someone helps

  • Getting the sum of the elements in an array

    Hello all,
    Any ideas on how to easily get the sum of the elements of an array of floating points (or any data type for that matter ) this is to be part of a method.
    arrayName (float [] floaters)
    Thanks

    int total=0;
    for(int a=0; a<array.length; a++){
      total=total+array[a];
    }now is that so hard?
    or even as a method
    public int addUp(int[] array){
       int total=0;
       for(int a=0; a<array.length; a++){
          total=total+array[a];
       return total;
    }to be used as
    int total=addUp(array);just write your own!

  • How to get the values of all elements and sub elements from  following xml

    how to get the values of all elements and sub elements from following xml...
    <?xml version="1.0" encoding="UTF-8" ?>
    <List_AML_Finacle xmlns="http://3i-infotech.com/Cust_AML_Finacle.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://3i-infotech.com/Cust_AML_Finacle.xsd List_AML_Finacle.xsd">
    <TransactionID>TransactionID</TransactionID>
    <Match>
    <Src_Matched_Field>Src_Matched_Field</Src_Matched_Field>
    <List_Matched_Field>
    <FSFM_Matches>
    <NUMBER>NUMBER</NUMBER>
    <TERROR>TERROR</TERROR>
    <TU>TU</TU>
    <NAMEU>NAMEU</NAMEU>
    <DESCRIPT>DESCRIPT</DESCRIPT>
    <KODCR>KODCR</KODCR>
    <KODCN>KODCN</KODCN>
    <AMR>AMR</AMR>
    <ADDRESS>ADDRESS</ADDRESS>
    <SD>SD</SD>
    <RG>RG</RG>
    <ND>ND</ND>
    <VD>VD</VD>
    <GR>GR</GR>
    <YR>YR</YR>
    <MR>MR</MR>
    <CB_DATE>CB_DATE</CB_DATE>
    <CE_DATE>CE_DATE</CE_DATE>
    <DIRECTOR>DIRECTOR</DIRECTOR>
    <FOUNDER>FOUNDER</FOUNDER>
    <TERRTYPE>TERRTYPE</TERRTYPE>
    </FSFM_Matches>
    <OfacMatchDetails>
    <UID>UID</UID>
    <TITLE>TITLE</TITLE>
    <SDNTYPE>SDNTYPE</SDNTYPE>
    <REMARKS>REMARKS</REMARKS>
    <ID_UID>ID_UID</ID_UID>
    <IDTYPE>IDTYPE</IDTYPE>
    <IDNUMBER>IDNUMBER</IDNUMBER>
    <IDCOUNTRY>IDCOUNTRY</IDCOUNTRY>
    <ISSUEDATE>ISSUEDATE</ISSUEDATE>
    <EXPIRATIONDATE>EXPIRATIONDATE</EXPIRATIONDATE>
    <ADDRESS1>ADDRESS1</ADDRESS1>
    <ADDRESS2>ADDRESS2</ADDRESS2>
    <ADDRESS3>ADDRESS3</ADDRESS3>
    <CITY>CITY</CITY>
    <STATEORPROVINCE>STATEORPROVINCE</STATEORPROVINCE>
    <POSTALCODE>POSTALCODE</POSTALCODE>
    <COUNTRY>COUNTRY</COUNTRY>
    </OfacMatchDetails>
    </List_Matched_Field>
    </Match>
    </List_AML_Finacle>

    avoid multi post
    http://forum.java.sun.com/thread.jspa?threadID=5249519

  • Query to get the data of all the columns in a table except any one column

    Can anyone please tell how to write a query to get the data of all the columns in a table except one particular column..
    For Example:
    Let us consider the EMP table.,
    From this table except the column comm all the remaining columns of the table should be listed
    For this we can write a query like this..
    Select empno, ename, job, mgr, sal, hiredate, deptno from emp;
    Just to avoid only one column, I mentioned all the remaining ( 7 ) columns of the table in the query..
    As the EMP table consists only 8 columns, it doesn't seem much difficult to mention all the columns in the query,
    but if a table have 100 columns in the table, then do we have to mention all the columns in the query..?
    Is there any other way of writing the query to get the required result..?
    Thanks..

    Your best best it to just list all the columns. Any other method will just cause more headaches and complicated code.
    If you really need to list all the columns for a table because you don't want to type them, just use something like...
    SQL> ed
    Wrote file afiedt.buf
      1  select trim(',' from sys_connect_by_path(column_name,',')) as columns
      2  from (select column_name, row_number() over (order by column_id) as column_id
      3        from user_tab_cols
      4        where column_name not in ('COMM')
      5        and   table_name = 'EMP'
      6       )
      7  where connect_by_isleaf = 1
      8  connect by column_id = prior column_id + 1
      9* start with column_id = 1
    SQL> /
    COLUMNS
    EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,DEPTNO
    SQL>

  • Get the sum/product of two UDF rows before adding A/R Invoice

    Hi Everyone,
    I am making some tests here where I am trying to get the sum or product of two UDF rows in a service type A/R invoice where I need to get the product before i even add the document.
    The query goes like:
    SELECT T0.[U_UDF1] * T0.[U_UDF2] FROM INV1 T0 WHERE T0.[U_UDF1] = $[INV1.U_UDF1]
    It did not work. Is this possible?
    Thanks,
    Derrick

    Before you add a transaction, the values you specify in the screen are not stored into the database. In an FS you can use SQL statements but in these statements you can refer only to the actual header or row level data with the special expressions starting with $. The system replaces these expressions with a constant containing the actual value before executing the SQL string.
    So there is no possibility to sum the columns with FS before adding the document.
    Sorry, I didnu2019t read carefully your question and probably misunderstood it.
    Edited by: István K#rös on Jan 13, 2011 11:27 AM

  • Just get the spinning ball all the time in FCP

    When I use Final Cut Pro (newest update) I get the spinning ball all the time when I do ordinary things like dobbleclicking a videoclip (DVCpro HD) or a sequence.
    If I try to force quit FCP it seems like it quits, the report problem to Apple screen appears, but I have to force shutdown the whole computer, because even after I have force quit FCP, it still appears like it is running in the dock, and I am not able to start it again before I have restartet the computer.
    I had this problem earlier, so yesterday I formated and reinstalled the whole system, but the problem continues. Its quite frustrating that I cant use Final Cut Pro on my new MacBook pro, 2,4GHZ, 4GB ram.

    Mac Spinning Wheel https://forums.adobe.com/message/5470608
    -Similar in Windows https://forums.adobe.com/message/5853430
    or
    Creative Cloud chat support (all Creative Cloud customer service issues)
    http://helpx.adobe.com/x-productkb/global/service-ccm.html

  • How to get the sum of  a column in a table layout region

    i have page table layout region and i have many rows in that ...i have a column say xyz now i want the sum of all xyz in all rows ...is that possible ..if it is how..????
    please help me out in this issues...so that i can proceed further with my work..im stuck otu here....if the solution r there in the devguide please tell me where it is ..i mean under which section...bcoz it 1400page document...

    If you are mentioning about table/advanced table region you can enable totalling in those regions. Please check the Table / Advanced Table section as appropriate in Chapter 4 of the dev guide.
    If it is not a table / advancedTable then you will have to programmatically total the column value and display it in the appropriate cell.

  • How can i get the list of all users present in the LDAP

    Hi Experts,
    How can i get the list of all users present in the LDAP ?
    Is there any API or function Code to get all user list??
    Please help me out!!!
    Help will be rewarded

    Well it will depend on exactly where your UME configuration points to in the LDAP tree but yes, it is possible to get all users.  Something like the following should do it:
    import com.sap.security.api.*;
    import com.sapportals.portal.prt.component.*;
    IUserFactory iuf;
    ISearchResult isr;
    IUser user
    String userid;
    iuf = UMFactory.getUserFactory();
    isr = iuf.getUniqueIDs();
    you will need to iterate the ISearchResult object but you can get IUser objects by
    userid = (String)isr.next();
    user = iuf.getUser(userid);
    then you can imanipulate / identify / or whatever you need with the user object
    Haydn

  • How can i get the list of all users present in the UME ?

    Hi Experts,
    How can i get the list of all users present in the UME ?
    Is there any API or function Code to get all user list??
    Please help me out!!!
    Help will be rewarded
    -pankaj chouhan

    Hi Pankaj,
    find the official NetWeaver security javadocs (including access to UME) <a href="http://help.sap.com/javadocs/NW04S/current/se/index.html">here</a>. Look for classs UMFactory and proceed from there.
    Best regards,
    Martin

  • I d/l your mozilla firefox today and now I get the error 0x80070002 all the time...how do I fix that?

    I downloaded mozilla firefox today and now I get the error 0x80070002 all the time, and I cannot use system restore because of it. How do I fix that so that my computer works right again. I was restoring because after I d/l your mozilla today, I lost all of my contacts in my msn email...just been tearing my hair out over this and it is soo darn frustrating. Tell me how to fix this. Marilyn

    Hi,
    The error is totally unrelated to Firefox. Please see [http://support.microsoft.com/kb/910336 this]. The [http://answers.microsoft.com/en-us Windows OS forum] will also be helpful.
    Please also check the downloaded file by right-clicking > Properties > Digital Signatures, which should say '''Mozilla Corporation''' and '''This digital signature is ok''' in '''Details'''. You can download Firefox from a known site like e.g. https://www.mozilla.org/en-US/firefox/new/
    You can try to Reset Firefox which would hopefully display the missing features, all (contacts, emails, settings etc.) of which are actually stored at the MSN site and are temporarily displayed by Firefox every time the site is accessed.
    The Reset Firefox feature can fix many issues by restoring Firefox to its factory default state while saving your essential information.
    Note: ''This will cause you to lose any Extensions, Open websites, and some Preferences.''
    To Reset Firefox do the following:
    #Go to Firefox > Help > Troubleshooting Information.
    #Click the "Reset Firefox" button.
    #Firefox will close and reset. After Firefox is done, it will show a window with the information that is imported. Click Finish.
    #Firefox will open with all factory defaults applied.
    Further information can be found in the [[Reset Firefox – easily fix most problems]] article.
    Did this fix your problems? Please report back to us!

  • 9I: How can get the names of all objects in a package header? [RESOLVED]

    Is there a way to get the names fo all objects (function, procedures) from package header
    select * from user_objects only gives the the header name, I need the object in the header.
    John
    Message was edited by:
    johnminkjan

    Here is an example with dbms_output package!
    SQL> select owner, object_name,procedure_name from all_procedures
      2  where  object_name='DBMS_OUTPUT';
    OWNER                          OBJECT_NAME                    PROCEDURE_NAME
    SYS                            DBMS_OUTPUT                    GET_LINES
    SYS                            DBMS_OUTPUT                    GET_LINE
    SYS                            DBMS_OUTPUT                    NEW_LINE
    SYS                            DBMS_OUTPUT                    PUT_LINE
    SYS                            DBMS_OUTPUT                    PUT_LINE
    SYS                            DBMS_OUTPUT                    PUT
    SYS                            DBMS_OUTPUT                    PUT
    SYS                            DBMS_OUTPUT                    DISABLE
    SYS                            DBMS_OUTPUT                    ENABLE
    9 rows selected.
    "or"
    SQL> desc dbms_output

  • How to get the list of all process order which are settled?

    Hello Friends,
    Is there any  standard report available to get the list of all settled  Process Order or  Production order?
    Thanking all of you in advance.
    Regards,
    Jitendra

    Hi,
    You can the below standardreports for knowing the list of Settled Process Orders :
    1. Use Tcode : COOIS and in the selection fields provide the Process Order Type, Plant and System Status As " SETT" and execute the same . System will list all the Process Orders which were settled so far.
    2. Use Tcode : CO26 with selection fields as above.
    Hope this will suffice your reqt.
    Regards
    radhak mk

Maybe you are looking for