Aggregation Function

I followed an example on the web and created a LIST() aggregation function to transpose rows to a comma delimited string. After certain length, the result appears to be out of order. I thought it was parallel_enable issue, but it's the same after I removed the clause from CREATE FUNCTION statement.
For example, the following SQL
SELECT LIST(column_name) FROM user_tab_columns
WHERE table_name='TEST' ORDER BY column_id
generate the following string:
c122,c123,c124,...,c1,c2,c3,...,c121
What should I do to correct this behavior? Thanks.
Here is the script:
create or replace type ListType as object
(list varchar2(4000),
static function ODCIAggregateInitialize(sctx IN OUT ListType) return number,
member function ODCIAggregateIterate(self IN OUT ListType, value IN varchar2) return number,
member function ODCIAggregateTerminate(self IN ListType, returnValue OUT varchar2, flags IN number) return number,
member function ODCIAggregateMerge(self IN OUT ListType, ctx2 IN ListType) return number
create or replace type body ListType
is
static function ODCIAggregateInitialize(sctx IN OUT ListType)
return number is
begin
sctx := ListType(null);
return ODCIConst.Success;
end;
member function ODCIAggregateIterate(self IN OUT ListType, value IN varchar2)
return number is
begin
self.list := self.list || ',' || value;
return ODCIConst.Success;
end;
member function ODCIAggregateTerminate(self IN ListType, returnValue OUT varchar2, flags IN number)
return number is
begin
returnValue := rtrim(ltrim(self.list,','),',');
return ODCIConst.Success;
end;
member function ODCIAggregateMerge(self IN OUT ListType, ctx2 IN ListType)
return number is
begin
self.list := self.list|| ',' || ctx2.list;
return ODCIConst.Success;
end;
end;
create or replace function list(input varchar2) return varchar2
parallel_enable aggregate using ListType;
grant EXECUTE on list to PUBLIC
/

in 10g, you could use something like
regexp_replace( list(distinct to_char(column_id,'0000')||':'||column_name), '([:[digit]:]){4}:')
if you need to support 9i, you cannot use regular expression, but you can write your own function and concatenated substr. kind of loop with instr(:) and substr()
HTH
Laurent
Message was edited by:
Laurent Schneider
but, if you need to sort, use ORDER BY. my solution is a not recommended, it is a very dirty trick
Message was edited by:
Laurent Schneider
use order by within your aggregate function, to sort the resultset each time, as advised by tom kyte in the link above

Similar Messages

  • Aggregation function for field in ALV Webdynpro ABAP

    Dear all,
    Can I create aggregation function on one field of ALV WDA which that is currency type field and then display the result based on currency key field?
    i've tried using code as shown below
      lo_wd_field = lo_model->if_salv_wd_field_settings~get_field( 'TOTAL' ).
      DATA: lo_field_aggr TYPE REF TO cl_salv_wd_aggr_rule.
      lo_field_aggr = lo_wd_field->if_salv_wd_aggr~create_aggr_rule( ).
      CALL METHOD lo_field_aggr->set_aggregation_type
        EXPORTING
          value = if_salv_wd_c_aggregation=>aggrtype_total.
      lo_wd_field->set_reference_field_type( if_salv_wd_c_field_settings=>reffieldtype_curr ).
      lo_wd_field->set_reference_field( 'WAERS' ).
    and then i've tried enabled standard function as shown below
    lo_model->if_salv_wd_std_functions~set_aggregation_allowed( abap_true ).
    But Why result of aggregation is not formatted based on currency key?
    Best regards,
    Agnis Virtinova Avency

    Hi Virtonova,
    My requirement is also simillar.
    I want to aggregate total based on Currency key.
    In the total for sub groups and final total with out any text or Description getting only single or double or triple ( dots ). .
    Is it possible to populate / change with useful text or decription for those rows.
    I am not getting Currency type after the total/sub totals.
    how to fix this in ALV list after using aggregate for the ALV.
    Thanks in advance.
    Dav

  • Create a View with Aggregation Function (COUNT)

    I've been looking up and down for a way to create a view with a few basic fields and some other fields containing aggregation function.
    For instance:
    To display a view that contain all the Contract Agreement and the corresponding count of the PO releases.
    Agreement Nbr, Total PO releases
    I need this view so that I can create a search help with this view.
    I found something about the "CREATE VIEW" statement, but I don't have any idea how to use it.
    Any helps toward this matter is very much appreciated, thanks.

    Hello Aldern
    I guess you have read about the SQL statement "CREATE VIEW". When we create a view in the dictionary this SQL statement is finally called to create the view on the DB. Thus, since we do not have any aggregation options in views you cannot achieve what you want using views.
    The solution for your problem is to create a <b>search help</b> having a <b>search help exit</b>. Within the exit you can do your aggregation functions and add these values to the displayed search help data.
    Regards
      Uwe

  • Dimension table to support Hierarchy and the aggregation functions

    Hello expert,
    Now I seem to know why those aggregation functions e.g. SUM, COUNT failed whenever the report is executed.
    I have a fact table REJECT_FACT contains all the information of rejects:
    Reject ID
    Reject Category
    Reject Code
    Reject Desc
    Site Desc
    Site Code
    Region Desc
    Age Group
    Reject Date
    So I created a alias REJECT_DIM based on REJECT_FACT. After several trials, I think that the aggregation functions do not work with alias because after I remove the REJECT_DIM, the aggregation seem working.
    Is my concept right? Or I am missing something? I don't understand that the data model for datawarehouse should be simple, why do we need to create many dimension tables to support the hierarchy?

    Hello expert,
    Thank you very much for your reply.
    Actually the data model is very simple. There is only one physical table REJECT_FACT. The structure is as follows:
    Reject ID (NUMBER)
    Reject Category (VARCHAR2)
    Reject Code (VARCHAR2)
    Reject Code Desc (VARCHAR2)
    Site Desc (VARCHAR2)
    Site Code (VARCHAR2)
    Region Desc (VARCHAR2)
    Age Group (VARCHAR2)
    Reject Date (DATE)
    The hierarchy required is as follows:
    Reject Category -> Reject Code Desc -> Site Desc -> Region Desc -> Age Group -> Reject Date.
    I want to produce count on each hierachy level.
    How to populate the hierachy structure effectively?
    Thanks......

  • How to optimize a MDX aggregation functions containing "Exists"?

    I have the following calculated measure:
    sum(([D Player].[Player Name].[All],
    exists([D Match].[Match Id].children,([D Player].[Player Name].currentmember,[Measures].[In Time]),"F Player In Match Stat" ))
    ,[Measures].[Goals])
    Analyzing this calculated measure (the one with "nonempty") in MDX Studio shows "Function
    'Exists' was used inside aggregation function - this disables block computation mode".
    Mosha Pasumansky spoke about this in one of his posts titled "Optimizing
    MDX aggregation functions" where he explains how to optimize MDX aggregation functions containing "Filter",
    "NonEmpty", and "Union", but he said he didn't have time to write about Exists, CrossJoin, Descendants, or EXISTING (he posted this in Oct. 2008 and the busy man didn't have time since that date :P )... so anyone knows an article that continues
    on what Mosha miss or forgot? how to optimize a MDX aggregation function containing "Exists"? what can I do to achieve the same as this calculated measure but in block mode not cell-by-cell mode ?

    Sorry for the late replay.
    I didn't check if your last proposed solution is faster or not, but I'm sorry to say that it gave the wrong result, look at this:
    Player Name
    Players Team
    Goals Player Scored with Team
    A
    Team's Goals in Player's Played Matches
    Lionel Messi
    Argentina
    28
    28
    110
    Lionel Messi
    Barcelona
    341
    330
    978
    The correct result should be like the green column. The last proposed solution in the red column.
    If you look at the query in my first post you will find that the intention is to find the total number of goals a team scored in all matches a player participated in. So in the above example Messi scored 28 goals for Argentina (before the last world cup:)
    )  when the whole Argentinian team scored 110 goals (including Messi's goals) in those matches that Messi played even one minute in.

  • Aggregation Function With Joining

    Hi all,
    I've the following SQL Query and I want to add a join with it:
    SELECT Collected_Goods.ProductId, SUM(Collected_Goods.Amount)
    FROM Collected_Goods
    GROUP BY Collected_Goods.ProductIdand I want to replace or add (but replace is better) the Collected_Goods.ProductId with a Products.Name where the product name appears in another table called products. Also I want the aggregation function SUM to work on Collected_Goods.ProductId
    The FK in Collected_Goods to Products is Collected_Goods.ProductId and Products.Id
    Thanks in advance
    Edited by: ZiKaS on Dec 30, 2008 2:05 AM

    The output for the above one is like this
    Collected_Goods.ProductId     |     SUM(Amount)
                                 1           |        60     
                                 2           |        32
                                 .            |         .
                                 .            |         .
                                 .            |         .
    I want it to be something link this
    Products.Name                     |     SUM(Amount)
                                 Milk        |        60     
                                 Butter    |        32
                                 .            |         .
                                 .            |         .
                                 .            |         .                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • User Aggregated Function in Discoverer

    Hi.
    I'm trying to use an "User Aggregated Function" in Discoverer. This function concatenates a varchar field, and I want to use as a max(), min() or count() functions, but Discoverer always write this function in the group block of the query, and the databse generates an error.
    This is the user agrgegated function:
    CREATE OR REPLACE function DDS_UXXIINV.var_agg (input varchar2) return varchar2
    parallel_enable aggregate using agg_t;
    The package agg_t is defined as:
    create or replace type agg_t as object (
    str_agg varchar2(4000),
    static function ODCIAggregateInitialize(sctx in out agg_t)
    return number,
    member function ODCIAggregateIterate (self in out agg_t,
    value in varchar2 )
    return number,
    member function ODCIAggregateTerminate (self in agg_t ,
    return_value out varchar2,
    flags in number )
    return number,
    member function ODCIAggregateMerge(self in out agg_t,
    ctx2 in agg_t )
    return number
    create or replace type body agg_t is
    static function ODCIAggregateInitialize(sctx in out agg_t)
    return number is
    begin
    sctx := agg_t(null);
    return ODCIConst.Success;
    end;
    member function ODCIAggregateIterate(
    self in out agg_t, value in varchar2)
    return number is
    begin
    str_agg := str_agg || value;
    return ODCIConst.Success;
    end;
    member function ODCIAggregateTerminate(self in agg_t,
    return_value out varchar2, flags in number) return number is
    begin
    return_value := str_agg;
    return ODCIConst.Success;
    end;
    member function ODCIAggregateMerge(self in out agg_t,
    ctx2 in agg_t) return number is
    begin
    str_agg := str_agg || ctx2.str_agg;
    return ODCIConst.Success;
    end;
    end;
    When I use this functions (as a calculated field) Discoverer generates this statment:
    select var_agg(field1), field2 form table group by var_agg(field1), field2;
    I want this statement:
    select var_agg(field1), field2 form table group by field2;
    Sometimes Oracle generates a error messages saying that there's a wrong combinations of joins (translated from spainsh)
    Regards
    Óscar Blanco

    Hi,
    Unfortunately, you cannot import user defined group functions into Discoverer, Discoverer does not understand them.
    Rod West

  • How to disable Row label from the aggregation function in Pivot table

    Hello everyone,
    I have table in Power Pivot like shown below:
    Item_Name
    Category
    Vendor
    Sales_Amount
    Item 1
    Category 1
    Vendor 1
    30
    Item 2
    Category 1
    Vendor 2
    25
    Item 3
    Category 2
    Vendor 3
    50
    Item 3
    Category 2
    Vendor 3
    60
    Item 3
    Category 2
    Vendor 3
    20
    Item 2
    Category 1
    Vendor 2
    10
    Item 2
    Category 1
    Vendor 2
    30
    Item 2
    Category 1
    Vendor 2
    100
    Item 2
    Category 1
    Vendor 1
    20
    By using above table i have to create Rank(Based on Sales amount) by Category and Item name in Pivot table, i have done easily like added two dimension attribute(Category, Item_Name) into row label and Sales_Amount into aggregation tab then I calculated
    rank:=RANKX(ALL(Sales[Item_Name]),[Sum of Sales_Amount]) so finally pivot table looks like shown below:
    But end user want to see the vendor name also in the pivot table but the Rank suppose to be based on Sales amount by Category and Item name. if i added the vendor name also into the row label, rank calculated based on on Sales amount by Category, Item
    name and vendor.
    I would be really grateful if anyone advise how to fix this problem as it will be helpful my most of the reports.
    Regards,
    Robert 

    Darren Gosbell,
    Thanks for your reply.
    Item_Name
    Category
    Vendor
    Sales_Amount
    Item 1
    Category 1
    Vendor 1
    30
    Item 2
    Category 1
    Vendor 2
    25
    Item 3
    Category 2
    Vendor 3
    50
    Item 3
    Category 2
    Vendor 3
    60
    Item 3
    Category 2
    Vendor 3
    20
    Item 2
    Category 1
    Vendor 2
    10
    Item 2
    Category 1
    Vendor 2
    30
    Item 2
    Category 1
    Vendor 2
    100
    Item 2
    Category 1
    Vendor 2
    20
    Item 4
    Category 1
    Vendor 2
    3
    Item 4
    Category 1
    Vendor 2
    50
    Item 4
    Category 1
    Vendor 2
    3
    The above is my new source data.
    I used this function to calculate  Rank:=RANKX(ALL(Sales[Item_Name]),[Sum of Sales_Amount])
    and also used yours below:  
    Rank2:=RANKX(SUMMARIZE(ALL(Sales),[Item_Name],[Category]),CALCULATE([Sum of Sales_Amount],ALLEXCEPT(Sales,Sales[Item_Name],Sales[Category])))
    The Preceding screenshot is the result of our two function but i wanna pivot table like shown below:
    Could please help me to fix it out.

  • Is it possible to use aggregation function in SQ Sap query?

    I need to create a sap query like using SELECT MAX(begda) statement.
    Please teach me how...
    Thank u in advance..

    Hi Ella,
    You can very well use the aggregate functions in sql which is usually a performance tuning technique.
    A calculation that is made on several records or cells of data. SUM, AVG, MAX, MIN and COUNT are examples of aggregate functions that are used in spreadsheets and database programs.
    SELECT ( ( ] ...
    MAX: returns the maximum value of the column
    MIN: returns the minimum value of the column
    AVG: returns the average value of the column
    SUM: returns the sum value of the column
    COUNT: counts values or lines as follows:
    · COUNT( DISTINCT ) returns the number of different values in the column.
    · COUNT( * ) returns the total number of lines in the selection.
    Ex:    DATA: fldate LIKE sbook-fldate,
          count  TYPE i,
          avg    TYPE p DECIMALS 2,
          max    TYPE p DECIMALS 2.
    SELECT fldate COUNT( * ) AVG( luggweight ) MAX( luggweight )
           FROM sbook
           INTO (fldate, count, avg, max)
           WHERE carrid = 'LH' AND
                 connid = '0400'
           GROUP BY fldate.
      WRITE: / fldate, count, avg, max.
    ENDSELECT.
    For further info:
    http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3990358411d1829f0000e829fbfe/content.htm
    http://help.sap.com/abapdocu/en/ABAPSELECT_AGGREGATE.htm
    Thanks and Regards
    Srikant.P
    Edited by: SRIKANTH P on May 27, 2009 9:41 AM

  • Double aggregation in a single query block doesn't make any sence.

    How can I argue with something that apparently has been cast in stone by ANSI SQL committee? Well the answer is famous: "Search any park in any city: you'll find no statue of committee".
    OK, why
    select count(1) from (
    select deptno from emp
    group by deptno
    is an easy to understand query, and why
    select count(count(*)) from emp
    group by deptno
    is not? I already mentioned one reason why count shouldn't accept any arguments, therefore count(count(*)) is a nonsence.
    The other reason is that aggregation without grouping is essentially aggregation within a single group. Once you realize that
    select sum(1) from emp
    is the same as
    select sum(1) from emp
    group by -1
    (where -1 or any other constant for that matter is a dummy pseudocolumn), then it becomes obvious that what we are doing in the infamous
    select count(count(*)) from emp
    group by deptno
    is a query with two blocks
    select count(1) from (
    select deptno from emp
    group by deptno
    ) group by -1
    We are not allowed to combine two "group by" into a single query, aren't we?

    Aggregate function always goes together with grouping. Grouping can partition the set of rows into many classes or a single class. Therefore, if we have 2 nested aggregation functions, we'd better be able to identify the corresponding groupings easily:
    select state, avg(min(tax_return)) from household
    group by city, state then statewhich is a shorthand for
    select state, avg(m) from (
       select city, state, min(tax_return) m
       from household
       group by city, state
    ) group by stateSpeaking of double aggregation, it is frequent in graph queries. The part explosion query is posted repeatedly virtually every month on this fine forum:-) The part explosion is double aggregation: multiply the quantities along each path in the assembly hierarchy. Then add the quantities along alternative paths. Likewise, finding a shortest path between two nodes in a graph is double aggregation query. First, we calculate the length buy adding the distances along each path, and then we choose a path with minimal length. Wouldn't it be nice to have this double aggregation wired into the connect by syntax? Note that connect_by_path is a surrogate aggregate which concatenates strings. People invent all kind of functions which parse this path and make other aggregates out of this value (such as sum and product).

  • OBIEE: Incorrect SQL - with count function uses ORDER BY instead GROUP BY

    I made a basic report that is a client count; I want to know how many clients the company have.
    But, when I run this report, OBIEE generates a ORDER BY sentence, instead a GROUP BY. Remember that I'm using count function, that is a agregation.
    The SQL generated was:
    select 'N0' as c1,
    count(*) as c2
    from
    (select distinct T1416.CLIENT_INTER_KEY as c1
    from
    (select *
    from prd.D_SERVICE where SOURCE_SYS in ('ARBOR','PPB') and DW_SERV_ST_ID in (100000003,100000009)) T1836,
    (select *
    from prd.D_CLIENT) T1416,
    (select *
    from prd.D_CUSTOMER_ACCOUNT where SOURCE_SYS In ('ARBOR','PPB')) T1515
    where ( T1416.DW_CLIENT_ID = T1515.DW_CLIENT_ID and T1515.DW_CUST_ACCT_ID = T1836.DW_CUST_ACCT_ID and T1836.MSISDN = '917330340' )
    ) D1
    order by c1
    The error that I receive is:
    "Query Status: Query Failed: [nQSError: 16001] ODBC error state: S1000 code: -1005018 message: [Sybase][ODBC Driver][Adaptive Server Anywhere]Illegal ORDER BY item Order Item: 'N0',
    -- (opt_OrderBy.cxx 429) .
    [nQSError: 16011] ODBC error occurred while executing SQLExtendedFetch to retrieve the results of a SQL statement."
    If I substitute ORDER BY with GROUP BY and test it in Sybase, Ithe query runs without any problem.
    select 'N0' as c1,
    count(*) as c2
    from
    (select distinct T1416.CLIENT_INTER_KEY as c1
    from
    (select *
    from prd.D_SERVICE where SOURCE_SYS in ('ARBOR','PPB') and DW_SERV_ST_ID in (100000003,100000009)) T1836,
    (select *
    from prd.D_CLIENT) T1416,
    (select *
    from prd.D_CUSTOMER_ACCOUNT where SOURCE_SYS In ('ARBOR','PPB')) T1515
    where ( T1416.DW_CLIENT_ID = T1515.DW_CLIENT_ID and T1515.DW_CUST_ACCT_ID = T1836.DW_CUST_ACCT_ID and T1836.MSISDN = '917330340' )
    ) D1
    group by c1
    Do you know why OBIEE generates this SQL??? Why uses, with a aggregation function, a ORDER BY and not a GROUP BY? How can I resolve this problem???
    Regards,
    Susana Figueiredo

    Verify your repository design and make sure that you have defined count aggregate on fact column. You would also need to define the content level of each dimension in fact table.

  • XPath expressions in aggreation functions behave different than I expect

    Hi,
    I'm having the following very simple schema:
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="a" type="AType" />
    <xs:complexType name="AType">
    <xs:sequence>
    <xs:element name="b" type="BType" />
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="BType">
    <xs:sequence>
    <xs:element name="c" type="CType" minOccurs="1" maxOccurs="unbounded" />
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="CType">
    <xs:all minOccurs="0">
    <xs:element name="d1" type="xs:double" />
    <xs:element name="d2" type="xs:double" />
    <xs:element name="d3" type="xs:double" />
    <xs:element name="d4" type="xs:double" />
    <xs:element name="d5" type="xs:double" />
    <xs:element name="d6" type="xs:double" />
    </xs:all>
    </xs:complexType>
    </xs:schema>
    Which I loaded using the following code:
    declare
    l_bfile bfile;
    begin
    l_bfile := bfilename('DIR_TEMP', 'simple.xsd');
    dbms_lob.open(l_bfile);
    dbms_xmlschema.registerschema('http://localhost/simple.xsd',l_bfile);
    dbms_lob.close(l_bfile);
    end;
    Then I created the table "simple" as follows:
    CREATE TABLE simple OF XMLTYPE XMLSchema "http://localhost/simple.xsd" ELEMENT "a";
    And I loaded the following XML document:
    <?xml version="1.0"?><a>< b>
    <c><d1>0</d1></c>
    <c><d1>1</d1></c>
    <c><d1>2</d1></c>
    <c><d1>3</d1></c>
    <c><d1>4</d1></c>
    <c><d1>5</d1></c>
    <c><d1>6</d1></c>
    <c><d1>7</d1></c>
    <c><d1>8</d1></c>
    <c><d1>9</d1></c>
    </b></a>
    Which was loaded by the following code:
    DECLARE
    file bfile;
    charContent clob := ' ';
    targetFile bfile;
    charset_id number := 0;
    src_offset number := 1;
    dst_offset number := 1;
    lang_ctx number := DBMS_LOB.default_lang_ctx;
    warning number;
    BEGIN
    DBMS_OUTPUT.enable(10000);
    file := bfilename('DIR_TEMP','simple.xml');
    targetFile := file;
    DBMS_LOB.fileopen(targetFile,DBMS_LOB.file_readonly);
    DBMS_LOB.loadclobfromfile(charContent,targetFile,DBMS_LOB.getLength(targetFile),src_offset, dst_offset, charset_id, lang_ctx, warning);
    DBMS_LOB.fileclose(targetfile);
    INSERT INTO simple VALUES (xmltype(charContent));
    END;
    The function to be executed is the avg of d1. The solution if of course 4.5.
    The following queries give the correct answer:
    SELECT XMLQuery('for $i in /a return avg($i//d1)' PASSING OBJECT_VALUE RETURNING CONTENT) FROM simple;
    SELECT XMLQuery('for $i in /a return avg(//d1)' PASSING OBJECT_VALUE RETURNING CONTENT) FROM simple;
    SELECT XMLQuery('for $i in /a let $t := //d1 return avg($t)' PASSING OBJECT_VALUE RETURNING CONTENT) FROM simple;
    However, when I execute any of the following expressions, they return nothing (or to be exact: an empty row):
    SELECT XMLQuery('for $i in /a return avg($i/b/c/d1)' PASSING OBJECT_VALUE RETURNING CONTENT) FROM simple;
    SELECT XMLQuery('for $i in /a return avg($i//c/d1)' PASSING OBJECT_VALUE RETURNING CONTENT) FROM simple;
    SELECT XMLQuery('for $i in /a return avg(//c/d1)' PASSING OBJECT_VALUE RETURNING CONTENT) FROM simple;
    SELECT XMLQuery('for $i in /a let $t := //c/d1 return avg($t)' PASSING OBJECT_VALUE RETURNING CONTENT) FROM simple;
    I'm expecting that avg($i//c/d1) selects all d1 elements contained in a c element within the context of $i and return the average of those d1s. However, it doesn't seem to do so.
    When I remove the "avg" in the last query:
    SELECT XMLQuery('for $i in /a let $t := //c/d1 return $t' PASSING OBJECT_VALUE RETURNING CONTENT) FROM simple;
    it does return a list of all d1 elements, as I expect. However the aggragation function doesn't return the value as expected. I've tested with more aggregation functions (eg. min, max) and all are having the same effects.
    Can anyone explain me what I'm missing here, or point me to some documentation which explains it?
    I'm running:
    SQL*Plus: Release 10.2.0.3.0 - Production
    on
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Production
    With the Partitioning, OLAP and Data Mining options
    null
    Message was edited by:
    Tijink

    Did you also try to create the XMLSchema and the table and run the queries against that?Still, no difference for me:
    michaels>  declare
       l_clob   clob
          := '<?xml version="1.0" encoding="ISO-8859-1" ?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="a" type="AType" />
    <xs:complexType name="AType">
    <xs:sequence>
    <xs:element name="b" type="BType" />
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="BType">
    <xs:sequence>
    <xs:element name="c" type="CType" minOccurs="1" maxOccurs="unbounded" />
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="CType">
    <xs:all minOccurs="0">
    <xs:element name="d1" type="xs:double" />
    <xs:element name="d2" type="xs:double" />
    <xs:element name="d3" type="xs:double" />
    <xs:element name="d4" type="xs:double" />
    <xs:element name="d5" type="xs:double" />
    <xs:element name="d6" type="xs:double" />
    </xs:all>
    </xs:complexType>
    </xs:schema>';
    begin
       dbms_xmlschema.registerschema (schemaurl      => 'http://localhost/simple.xsd',
                                      schemadoc      => l_clob,
                                      gentypes       => false
    end;
    PL/SQL procedure successfully completed.
    michaels>  create table simple of xmltype xmlschema "http://localhost/simple.xsd" element "a"
    Table created.
    michaels>  insert into simple
         values (xmltype
                    ('<?xml version="1.0"?><a><b>
                <c><d1>0</d1></c>
                <c><d1>1</d1></c>
                <c><d1>2</d1></c>
                <c><d1>3</d1></c>
                <c><d1>4</d1></c>
                <c><d1>5</d1></c>
                <c><d1>6</d1></c>
                <c><d1>7</d1></c>
                <c><d1>8</d1></c>
                <c><d1>9</d1></c></b></a>'
    1 row created.
    michaels>  select xmlquery('for $i in /a return avg($i//d1)' passing  object_value returning content).getnumberval() res from simple
    union all
    select xmlquery('for $i in /a return avg(//d1)' passing  object_value returning content).getnumberval() res from simple
    union all
    select xmlquery('for $i in /a let $t := //d1 return avg($t)' passing  object_value returning content).getnumberval() res from simple
    union all
    select xmlquery('for $i in /a return avg($i/b/c/d1)' passing  object_value returning content).getnumberval() res from simple
    union all
    select xmlquery('for $i in /a return avg($i//c/d1)' passing  object_value returning content).getnumberval() res from simple
    union all
    select xmlquery('for $i in /a return avg(//c/d1)' passing  object_value returning content).getnumberval() res from simple
    union all
    select xmlquery('for $i in /a  let $t := //c/d1 return avg($t)' passing  object_value returning content).getnumberval() res from simple
           RES
           4,5
           4,5
           4,5
           4,5
           4,5
           4,5
           4,5
    7 rows selected.

  • How to use analytical functions inside a mapping

    Hello everybody. Here Isend you a trick that we are using for two years.
    If you want to use a function (for instance :ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...)) inside a mapping you must create an expression with in the INGRP1 the fields you are going to use in the window function and in the OUTGRP1 the function you want. Create an Out -attribute with the expressión and link it to a distinct operator (using a "distinct" you encapsulte the sql and you will be able to use the function inside a filter - in the where clause.). The distinct can eliminate some register (depends on the function). If you validate the expression an error will appear (don't worry about that, the mapping will be ok).
    But there is a limitation, you will not be able tou sum over, min over, max over (it detect that they are aggregator functions). Other limitation: the debugger doesn't run with this kind of functions.
    Please publish this information on "The Warehouse Builder Utility Exchange". Mi email is [email protected] (if you need more information)

    It is possible to add SUM, MIN, MAX functions also to OWB releases prior to Paris - You have to put them in double quotes - write "MIN" "MAX" "SUM" etc. The rest of the rules (adding cut-off operator after the expression - as DISTINCT, or UNION ALL) is analogical to with ROW_NUMBER()
    That means You can create mapping with following functionality:
    SELECT
    sum (salary) over (partition by DEPARTMENT) department_salary,
    salary,
    employee_id,
    employee_name
    FROM employees_salaries
    writing it this way in OWB:
    SELECT
    "SUM" (salary) over (partition by DEPARTMENT) department_salary,
    salary,
    employee_id,
    employee_name
    FROM employees_salaries
    Regards,
    Martin

  • How to Perform an Aggregate Function?

    Hi,
    I'm trying to define in Designer 6.5 an object with the following select: (example)
    sum (count (distinct REPORTING.table.object_name))
    the SQL parsing restitues me this error --> "The SQL can not perform an aggregate function on an expression containing an aggregate or a subquery".
    Can anyboby explain me the problem and above all how to solve it?
    Thanks
    Riccardo

    Hi,
    You cannot mix different aggregations functions in the same SQL expression: this is a SQL limitation for all databases.
    You need to use subselect to achieve your requirement.
    See the following example that works on SQL Server:
    Select sum(a._count) from
    (Select count (distinct cust_id) as _count from Club.dbo.Customer) a
    Regards,
    Didier

  • Nested Aggregation Problem

    I am using OBI 11g.
    Nested aggregation is not supported in some forms in the BI Server (RPD), but appears to be possible by putting the second aggr rule in an Answers column formula or pivot view column. However, I cannot get this to work. Looks like can even be done in the RPD with aggregation based on dimensions, as long as there is a standard aggregation function on the outside of the expression.
    The biggest problem with any of the above techniques is the BI Server does not push the outer aggregation rule to the DB engine (the generated SQL).
    In my case, consider a Referral Fact with Customer Dim and Referral Dim. I need to get # of Referrals per customer, filter that with a case statement to "bin" 1 Referral and >1 Referral, and then get # of Customers in each bin. So the first measure aggregation looks like:
    Other: COUNT (DISTINCT "Referral Key")
    Customer: "SUM( CASE WHEN "Referral Key" = 1 THEN 1 ELSE 0 END )"
    Or the logical measure just has the COUNT DISTINCT aggregation rule and an Answers column has the CASE statement with a SUM aggregation rule. Or use CASE WHEN "Referral Key" = 1 THEN "Customer Key" END and use COUNT DISTINCT instead of SUM.
    All these appear to return correct results, but they all perform the outer aggregation in the BI Server or Pivot engine instead of pushing to the generated SQL (DB engine).
    I can't find any problem in the DB Features. We are using SQL Server 2010.
    Thanks in advance for help.

    Hi AL,
    here is my requirement what i have been asked to get this output result.
    i have keyfigures KF1, KF2 and total KF.
    three characteristics dist,inch,load.
    dist-inch-load--KF1-KF2-Total KF                         
      5---A--010-0-----10=10                         
      5---A--120-20----20+10=30                         
    10--B---050-0-----50                         
    12--C---160-60----60                         
    13--D---270-70----70                         
    14--E---080-0-----80                         
    15--E---120-20----20+80=100                         
    15--E---230-30----302080=130     
    KF1 is the initial volume coming from the file directily.based on this keyfigure i have to calculate KF2,Total KF.     
    In order to calcuate KF2 and Total KF i have some conditions.which are mentioned below;
    KF2---> if  load=0 then KF2=0 elseif load>0 then KF2=KF1 ;
    Total KF--->if load=0 then Total KF=KF2KF1 elseif load>0 then KF2=KF2KF1
    How to achieve this dynamic summation.Do i have to do nested exception aggregation based on the above three characteristics. what would be the open options.please do help me.

Maybe you are looking for

  • Adding Folders to Library in Windows Vista

    I have recently replaced my notebook with one running Windows Vista, and have a fairly annoying problem with adding music to my iTunes library. All of my music is stored in a shared folder on the hard drive of a different computer on my home network.

  • How can I create multiple libraries on a windows 8 HP computer?

    I just got the newest generation Ipod Touch, and the itunes is not supported on my iMac G5. My parents have a Windows 8 HP computer. My dad's itunes account is on that computer. So what I want to do is use my external hardrive to sync it to my Window

  • Question: is there any way to get entity class in JPQL query

    Hello, I'm using J*dev 11gR1 adn JPA with EclipceLink*. Let's consider such example @Entity @Table(name="ANIMALS") @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public class Animal implements Serializable { @Entity @Table(name = "CATS") pu

  • Troubleshooting

    Hi, once again I am writing to report that since I have updtated to Adobe XI tool bar hides, and every time is necessary to press F9. Your answer was: Do you use Kaspersky? If so, install the latest version 15.0.1.415 of your Kaspersky software. I am

  • Windows 8 Install

    I have purchased windows 8 and already made it into a iso file, then went through bootcamp and partitioned my driver.... I then tried to instal windows and didn't click custom which didn't work so restarted my mac and I now can't get back to the wind