Prob with group by function

Hi frds
I wrote a code where there is a subquery in my select statement, when i use a group by function with my query it comes with an error
Example
This is how my select statement looks
SELECT
mt.subinventory_code,
item.description,
we.wip_entity_name,
SUM((mt.transaction_quantity)*-1),
sum(wro.required_quantity),
sum(wdj.start_quantity),
(SELECT SUM (transaction_quantity) FROM mtl_onhand_quantities
WHERE inventory_item_id = wro.inventory_item_id
AND organization_id = wro.organization_id) rm_stock
And my group by statement is of this way
group by
mt.subinventory_code,
item.description,
we.wip_entity_name
When i excute the query
It results in an error like this
ORA-00979: not a GROUP BY expression
When i remove the subquery from my select statement it works fine,but i want the result including the subquery plz help me

I don't know the implications, but give this a try.
SELECT we.wip_entity_name JOB_NO,
       mt.subinventory_code DEPARTMENT,
       msi1.segment1 assembly_item,
       msi1.description assm_desc,
       sum(wdj.start_quantity) ASSL_QTY,
       item.segment1 PART_CODE,
       item.description PART_DESCRIPTION,
       item.primary_uom_code UOM,
       sum(wro.required_quantity) REQUIRED_QTY,
       SUM((mt.transaction_quantity)*-1) ISSUED_QTY,
       mfg.meaning JOB_STATUS,
       SUM (mol.transaction_quantity) rm_stock
FROM mtl_material_transactions mt,
     mtl_system_items item,
     mtl_system_items msi1,
     wip_e0ntities we,
     wip_requirement_operations wro,
     mfg_lookups mfg,
     wip_discrete_jobs wdj
     mtl_onhand_quantities mol
WHERE mt.inventory_item_id = wro.inventory_item_id
and mt.inventory_item_id=item.inventory_item_id
AND item.inventory_item_id = wro.inventory_item_id
AND we.wip_entity_id = wro.wip_entity_id
AND wdj.wip_entity_id = we.wip_entity_id
AND mfg.lookup_code = wdj.status_type
AND mt.organization_id = :org_id
AND mt.inventory_item_id = wro.inventory_item_id
AND item.organization_id = wro.organization_id
AND mt.transaction_source_id = we.wip_entity_id
AND msi1.inventory_item_id = wdj.primary_item_id
AND msi1.organization_id = wro.organization_id
AND we.wip_entity_id = wro.wip_entity_id
AND we.organization_id = wro.organization_id
AND mfg.lookup_code = wdj.status_type
AND mfg.lookup_type = 'WIP_JOB_STATUS'
AND mt.transaction_type_id = 35
AND wro.department_id <> 1001
AND wro.required_quantity > transaction_quantity*-1
AND mol.inventory_item_id = wro.inventory_item_id
AND mol.organization_id = wro.organization_id
group by mt.subinventory_code,
         item.description,
         item.segment1,
         we.wip_entity_name,
         mfg.meaning,
         item.primary_uom_code,
         msi1.segment1 ,
         msi1.description;Cheers
Sarma.

Similar Messages

  • Can i use Lead function with Group by function

    I could use this query and get right ouput since i define product id =2000
    select product_id, order_date,
    lead (order_date,1) over (ORDER BY order_date) AS next_order_date
    from orders
    where product_id = 2000;
    But can i run this query by Group by Function
    for example
    select product_id, order_date,
    lead (order_date,1) over (ORDER BY order_date) AS next_order_date
    from orders
    group by product_id ;
    since data would be like and i need
    Product_id order Date
    2000 1-jan-09
    2000 21-jan-09
    3000 13-jan-09
    3000 15-jan-09
    4000 18-jan-09
    4000 19-jan-09
    output would be like for eg
    Product_id order Date Next_date
    2000 1-jan-09 21-jan-09
    3000 13-jan-09 15-jan-09
    4000 18-jan-09 19-jan-09

    Thanks everybody for ur help
    i could exactly mention what i requred
    create table SCHEDULER
    ( REF VARCHAR2(10),     
    NO NUMBER     ,
    PORT VARCHAR2(10),     
    ARRIVAL DATE     ,
    DEPARTURE DATE
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA0677',1,'KUWAIT','1-Sep-09','02-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA0677',2,'INDIA','5-Sep-09','07-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA0677',3,'COLUMBO','8-Sep-09','09-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA0677',4,'IRAN','10-Sep-09','12-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA0677',5,'IRAQ','14-Sep-09','15-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA0677',6,'DELHI','17-Sep-09','19-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA0677',7,'POLAND','21-Sep-09','23-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA0678',1,'INDIA','5-Sep-09','07-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA0678',2,'COLUMBO','8-Sep-09','09-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA0678',3,'IRAN','10-Sep-09','12-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA0678',4,'IRAQ','14-Sep-09','15-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA0678',5,'DELHI','17-Sep-09','19-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA0678',6,'POLAND','21-Sep-09','23-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA0678',7,'GOA','1-Oct-09','02-Oct-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2372',1,'INDIA','1-Sep-09','02-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2372',2,'KERALA','3-Sep-09','03-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2372',3,'BOMBAY','4-Sep-09','04-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2373',1,'INDIA','5-Sep-09','06-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2373',2,'ANDHERI','6-Sep-09','07-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2376',1,'INDIA','5-Sep-09','07-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2420',1,'INDIA','5-Sep-09','06-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2420',2,'ANDHERI','7-Sep-09','08-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2420',3,'BURMA','10-Sep-09','11-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2420',4,'BENGAL','11-Sep-09','12-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2445',1,'INDIA','4-Sep-09','05-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2445',2,'BURMA','7-Sep-09','09-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2498',1,'BENGAL','8-Sep-09','08-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2498',2,'COCHIN','11-Sep-09','11-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2498',3,'LANKA','12-Sep-09','12-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2498',4,'COLUMBO','13-Sep-09','15-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2498',5,'INDIA','17-Sep-09','18-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2505',1,'COLUMBO','5-Sep-09','06-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2505',2,'GOA','8-Sep-09','09-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2505',3,'INDIA','13-Sep-09','15-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2510',1,'INDIA','4-Sep-09     06-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2510',2,'BENGAL','8-Sep-09     09-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2510',3,'GOA','10-Sep-09     11-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2513',1,'INDIA','7-Sep-09','09-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2513',2,'USA','11-Sep-09','11-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2513',3,'UK','12-Sep-09','13-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2520',1,'INDIA','4-Sep-09','06-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2520',2,'BENGAL','8-Sep-09','09-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2520',3,'GOA','10-Sep-09','11-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2526',1,'INDIA','5-Sep-09','07-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2526',2,'DUBAI','10-Sep-09','11-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2526',3,'GOA','13-Sep-09','15-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2526',4,'OMAN','17-Sep-09','18-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2526',5,'INDIA','19-Sep-09','20-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2527',1,'BURMA','7-Sep-09','08-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2527',2,'INDIA','9-Sep-09','10-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2527',3,'ANDHERI','10-Sep-09','16-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2532',1,'SHARJAH','3-Sep-09','04-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2532',2,'AEDXB','5-Sep-09','05-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2533',1,'AESHJ','2-Sep-09','02-Sep-09');
    INSERT INTO SCHEDULER(REF,NO,PORT,ARRIVAL,DEPARTURE)
    VALUES('VA2533',2,'INDIA','3-Sep-09','03-Sep-09');
    COMMIT;
    Suppose these records shows the REF travelling from one location to another with respect to date
    We need to find out each REF GROUP WISE AND THE DATE OF TRAVELLING FOR SPECIFIED location travelling IE from STARTING FROM INDIA AND ENDING TO GOA
    OUTPUT SHOULD BE LIKE DATA SHOWN BELOW
    FROM LOCATION TO LOCATION
    REF , NO , PORT , ARRIVAL ,DEPARTURE , REF , NO , PORT , ARRIVAL , DEPARTURE
    VA0678     1 INDIA     5-Sep-09 07-Sep-09     VA0678 7 GOA 1-Oct-09 02-Oct-09     
    VA2510     1 INDIA     4-Sep-09 06-Sep-09     VA2510 3 GOA 10-Sep-09 11-Sep-09
    VA2520     1 INDIA     4-Sep-09 06-Sep-09     VA2520 3 GOA 10-Sep-09 11-Sep-09
    VA2526     1 INDIA     5-Sep-09 07-Sep-09     VA2526 3 GOA 13-Sep-09 15-Sep-09
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------

  • Case with group by function

    I have the following script pulling from the work order module(*where clause omitted):
    SELECT status,
    COUNT(distinct NUM) countofWO FROM wo
    GROUP BY status; Result set is: DS -1; WAPPR-2; INPRG-3;
    I have another script that pulls from the equipment module:
    select count(*) equipment_count from equipment; with result set 500
    I need a sql statement that will provide me with the following results:
    equipment_count - 500
    sum(countofWO) for all status - 6
    sum(countofWO) if status = DS - 1
    sum(countofWO) if status = DS and INPRG - 4
    sum(countofWO) if status = WAPPR and INPRG - 5;
    I started by creating multiple instances of the select statement with different where clauses and UNION'ed them. It took 30 minutes to execute. I tried to use the case statement, but had issues with the group by

    Hi,
    Welcome to the forum!
    Whenever you have a question, it helps to post:
    (1) The version of Oracle (and any other relevant software) you're using
    (2) A little sample data (just enough to show what the problem is) from all the relevant tables
    (3) The results you want from that data
    (4) Your best attempt so far (formatted)
    (5) The full error message (if any), including line number
    Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
    If you can present your problem using commonly available tables (for example, tables in scott schema, or views in the data dictionary), then you can omit (2).
    Formatted tabular output is okay for (3). Type these 6 characters:
    &#123;code&#125;
    (small letters only, inside curly brackets) before and after formatted text, to preserve spacing.
    Without the information above, the best I can do is guess.
    For the totals on the wo table, this might be what you want:
    SELECT       COUNT (DISTINCT num)                              AS all_status
    ,       COUNT (DISTINCT CASE WHEN status = 'DS'    THEN num END)     AS ds
    ,       COUNT (DISTINCT CASE WHEN status = 'DS'
                                OR   status = 'INPRG' THEN num END)     AS ds_inprg
    ,       COUNT (DISTINCT CASE WHEN status = 'WAPPR'
                          OR   status = 'INPRG' THEN num END)     AS wappr_inprg
    FROM       wo
    ;You might use a cross-join to get the data from the equipment table in the same result set. Without the information above, I can't tell.

  • Confusion in group by function

    Hi,
    I always have a doubt regarding the group by function i.e. if we are using a group by function and we want to display some columns which are not to be grouped by then how do we display those.
    Like for eg.
    to display last name, department no and average of salary for each department how should we proceed.
    I know we can display the department no, and avg(sal) but how abt the last name.
    Do we use a subquery?
    Any thoughts or explanaitions with example?
    Thanks

    hi, People often get confused with group by function.
    You have to be very clear about this that the group by must include all the columns that have been selected. If you want to use another column out of group by list then that column must be driven by the another table join or inline table join.
    bye

  • Prob with decode function

    hi iam having prob with the following decode function
    declare
    c varchar2(20);
    begin
    select decode(deptno,
    10, 'accounting',
    20,'Research',
    30 ,'sales',
    40,'operations','UNKNOWN') into c from dept where loc='DALLAS';
    dbms_output.put_line('DEPARTMENT in DALLAS'||c);
    select decode(deptno,
    10, 'accounting',
    20,'Research',
    30 ,'sales',
    40,'operations','UNKNOWN') into c from dept where loc='INDIA';
    dbms_output.put_line('DEPARTMENT IN INDIA'||c);
    end;
    iam getting no_data_found exception which is reasonable..but what happened to 'unknown' clause in decode function.
    thank u
    rajiv

    Please see the responses to your prob in decode function
    John

  • Function module Prob with kostl

    hi,good day guys.
    Iam using K_ORDER_SRULE_ADD for settelment rules. In this other function module  for read the fields one whic is K_DEFAULT_RULE_READ.. This is k_order_srule_add f.m source code as below as.
    .default rule table TKB2C is maintained as 'I_SRULES' therefore
    *.....aditional work area is needed.
          i_srules = srules.
    *.....fill COBL to find KONTY
          cobl-kokrs        = ld_kokrs.
          cobl-gsber        = srules-bus_area.
          cobl-bukrs        = srules-comp_code.
          cobl-saknr        = srules-gl_account.
          cobl-prctr        = srules-profit_ctr.
          cobl-kostl        = srules-costcenter.                     "here iam getting the cost center value
          cobl-aufnr        = srules-orderid.
          CALL FUNCTION 'CJPN_EXTERN_TO_INTERN_CONV'
            EXPORTING
              ext_num       = srules-wbs_element
            IMPORTING
              int_num       = cobl-ps_psp_pnr
            EXCEPTIONS
              error_message = 2
              OTHERS        = 1.
            EXIT.
          ENDIF.
          cobl-anln1        = srules-asset_no.
          cobl-anln2        = srules-sub_number.
          cobl-nplnr        = srules-network.
          cobl-vornr        = srules-activity.
          cobl-kdauf        = srules-sales_ord.
          cobl-kdpos        = srules-s_ord_item.
          cobl-kstrg        = srules-cost_obj.
          cobl-prznr        = srules-co_busproc.
    *.....get ASSIGN information in IT_DFTAB
          CLEAR konty.
          CALL FUNCTION 'K_DEFAULT_RULE_READ'        "this FM reads the fields and assining to the lt_dftab
            EXPORTING
              dfreg         = 'BAP'
              obart         = 'OR'
              i_cobl        = cobl
            IMPORTING
              e_konty       = konty
            TABLES
              dftab         = it_dftab                                           "iam not getting the costcenter[kostl] field..
            EXCEPTIONS
              error_message = 2
              OTHERS        = 1.
          IF ( sy-subrc <> 0 ).
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                    RAISING error_occurred.
            flg_leave = 'X'.
            EXIT.
          ENDIF.
    Based on lt_dftab fields. K_POSTING_RULE_INSERT f.m willbe insert the values.prob with costcenter.
    Edited by: balaji kiran on Apr 14, 2010 7:55 AM
    Edited by: balaji kiran on Apr 14, 2010 7:57 AM

    Hi,
    Could you explain how you did it?
    -Thanks

  • Case function with group by

    Hi,
      I am having a scenario like :
    Column 1:  BrokerList(dimension1)
    Column 2 : Broker(dimension2)
    Column 3 : Metric value(measure)
    so i am having a case when (dimension 3) Custodian = 'ss' then sum(metirc) group by dimension1,dimension2 but the result value is not matching
    BrokerList
    Broker
    Metric
    a1
    a
    10
    b
    20
    c
    30
    a1 :total
    60
    a2
    a
    50
    c
    60
    d
    10
    a2:total
    120
    Grand total
    180
    Here the metric is based on other case condition.. so the total value is not matching.. Is there any other way to do a case function with group by funtions. Please advise.
    regards,
    Guru

    Use filter on metric by ss value and then go for group by from Criteria
    something like
    sum(FILTER(metric USING (Custodian = 'ss')) by dimension1,dimension2)
    mark if helps
    ~ http://cool-bi.com

  • I just tried the 'group tabs' function but when I close a window and open a new one, the last page I viewed opens every single time. I can't remove or ignore the group tabs function and it automatically opens with it. How can I stop this?

    Before I attempted using the 'groups tab' function for the first time, there was no icon (unlike currently). There is now the icon with for the function yet I am unable to remove it or its function.

    Try a clean reinstall and delete the Firefox program folder and desktop shortcut before (re)installing a fresh copy of the current Firefox release.
    Download a fresh Firefox copy and save the file to the desktop.
    *Firefox 23.0: http://www.mozilla.org/en-US/firefox/all.html
    Uninstall your current Firefox version, if possible, to cleanup the Windows registry and settings in security software.
    *Do NOT remove personal data when you uninstall your current Firefox version, because all profile folders will be removed and you lose personal data like bookmarks and passwords from profiles of other Firefox versions.
    Remove the Firefox program folder before installing that newly downloaded copy of the Firefox installer.
    *(32 bit Windows) "C:\Program Files\Mozilla Firefox\"
    *(64 bit Windows) "C:\Program Files (x86)\Mozilla Firefox\"
    *It is important to delete the Firefox program folder to remove all the files and make sure that there are no problems with files that were leftover after uninstalling.
    *http://kb.mozillazine.org/Uninstalling_Firefox
    Your bookmarks and other personal data are stored in the Firefox profile folder and won't be affected by an uninstall and (re)install, but make sure that "remove personal data" is NOT selected when you uninstall Firefox.
    *http://kb.mozillazine.org/Profile_folder_-_Firefox
    *http://kb.mozillazine.org/Profile_backup
    *http://kb.mozillazine.org/Standard_diagnostic_-_Firefox#Clean_reinstall

  • Performance issues with pipelined table functions

    I am testing pipelined table functions to be able to re-use the <font face="courier">base_query</font> function. Contrary to my understanding, the <font face="courier">with_pipeline</font> procedure runs 6 time slower than the legacy <font face="courier">no_pipeline</font> procedure. Am I missing something? The <font face="courier">processor</font> function is from [url http://www.oracle-developer.net/display.php?id=429]improving performance with pipelined table functions .
    Edit: The underlying query returns 500,000 rows in about 3 minutes. So there are are no performance issues with the query itself.
    Many thanks in advance.
    CREATE OR REPLACE PACKAGE pipeline_example
    IS
       TYPE resultset_typ IS REF CURSOR;
       TYPE row_typ IS RECORD (colC VARCHAR2(200), colD VARCHAR2(200), colE VARCHAR2(200));
       TYPE table_typ IS TABLE OF row_typ;
       FUNCTION base_query (argA IN VARCHAR2, argB IN VARCHAR2)
          RETURN resultset_typ;
       c_default_limit   CONSTANT PLS_INTEGER := 100;  
       FUNCTION processor (
          p_source_data   IN resultset_typ,
          p_limit_size    IN PLS_INTEGER DEFAULT c_default_limit)
          RETURN table_typ
          PIPELINED
          PARALLEL_ENABLE(PARTITION p_source_data BY ANY);
       PROCEDURE with_pipeline (argA          IN     VARCHAR2,
                                argB          IN     VARCHAR2,
                                o_resultset      OUT resultset_typ);
       PROCEDURE no_pipeline (argA          IN     VARCHAR2,
                              argB          IN     VARCHAR2,
                              o_resultset      OUT resultset_typ);
    END pipeline_example;
    CREATE OR REPLACE PACKAGE BODY pipeline_example
    IS
       FUNCTION base_query (argA IN VARCHAR2, argB IN VARCHAR2)
          RETURN resultset_typ
       IS
          o_resultset   resultset_typ;
       BEGIN
          OPEN o_resultset FOR
             SELECT colC, colD, colE
               FROM some_table
              WHERE colA = ArgA AND colB = argB;
          RETURN o_resultset;
       END base_query;
       FUNCTION processor (
          p_source_data   IN resultset_typ,
          p_limit_size    IN PLS_INTEGER DEFAULT c_default_limit)
          RETURN table_typ
          PIPELINED
          PARALLEL_ENABLE(PARTITION p_source_data BY ANY)
       IS
          aa_source_data   table_typ;-- := table_typ ();
       BEGIN
          LOOP
             FETCH p_source_data
             BULK COLLECT INTO aa_source_data
             LIMIT p_limit_size;
             EXIT WHEN aa_source_data.COUNT = 0;
             /* Process the batch of (p_limit_size) records... */
             FOR i IN 1 .. aa_source_data.COUNT
             LOOP
                PIPE ROW (aa_source_data (i));
             END LOOP;
          END LOOP;
          CLOSE p_source_data;
          RETURN;
       END processor;
       PROCEDURE with_pipeline (argA          IN     VARCHAR2,
                                argB          IN     VARCHAR2,
                                o_resultset      OUT resultset_typ)
       IS
       BEGIN
          OPEN o_resultset FOR
               SELECT /*+ PARALLEL(t, 5) */ colC,
                      SUM (CASE WHEN colD > colE AND colE != '0' THEN colD / ColE END)de,
                      SUM (CASE WHEN colE > colD AND colD != '0' THEN colE / ColD END)ed,
                      SUM (CASE WHEN colD = colE AND colD != '0' THEN '1' END) de_one,
                      SUM (CASE WHEN colD = '0' OR colE = '0' THEN '0' END) de_zero
                 FROM TABLE (processor (base_query (argA, argB),100)) t
             GROUP BY colC
             ORDER BY colC
       END with_pipeline;
       PROCEDURE no_pipeline (argA          IN     VARCHAR2,
                              argB          IN     VARCHAR2,
                              o_resultset      OUT resultset_typ)
       IS
       BEGIN
          OPEN o_resultset FOR
               SELECT colC,
                      SUM (CASE WHEN colD > colE AND colE  != '0' THEN colD / ColE END)de,
                      SUM (CASE WHEN colE > colD AND colD  != '0' THEN colE / ColD END)ed,
                      SUM (CASE WHEN colD = colE AND colD  != '0' THEN 1 END) de_one,
                      SUM (CASE WHEN colD = '0' OR colE = '0' THEN '0' END) de_zero
                 FROM (SELECT colC, colD, colE
                         FROM some_table
                        WHERE colA = ArgA AND colB = argB)
             GROUP BY colC
             ORDER BY colC;
       END no_pipeline;
    END pipeline_example;
    ALTER PACKAGE pipeline_example COMPILE;Edited by: Earthlink on Nov 14, 2010 9:47 AM
    Edited by: Earthlink on Nov 14, 2010 11:31 AM
    Edited by: Earthlink on Nov 14, 2010 11:32 AM
    Edited by: Earthlink on Nov 20, 2010 12:04 PM
    Edited by: Earthlink on Nov 20, 2010 12:54 PM

    Earthlink wrote:
    Contrary to my understanding, the <font face="courier">with_pipeline</font> procedure runs 6 time slower than the legacy <font face="courier">no_pipeline</font> procedure. Am I missing something? Well, we're missing a lot here.
    Like:
    - a database version
    - how did you test
    - what data do you have, how is it distributed, indexed
    and so on.
    If you want to find out what's going on then use a TRACE with wait events.
    All nessecary steps are explained in these threads:
    HOW TO: Post a SQL statement tuning request - template posting
    http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
    Another nice one is RUNSTATS:
    http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551378329289980701

  • Automatic assignment responsible group partner function of Activities

    Hi,
    I need help on below requirement>>
    Automatic assignment responsible group partner function of Activities when status is set to u201CIncorrectly Assignedu201D.
    Thanks

    you can check with order status badi
    BR
    Radek

  • Sort order for group by functions

    I have table TAB1(notenum number, linenum number, linetext varchar2(100)).
    Each note can have multiple lines of text. Eg data
    NOTENUM     LINENUM     LINETEXT
    1     1     THIS IS LINE1.
    1     2     THIS IS LINE2.
    2     1     THIS IS LINE1 OF NOTE2.
    2     2     THIS IS LINE2 OF NOTE2.
    I need the text of lines of the most recent note (max notenum)
    <Note>THIS IS LINE1 OF NOTE2. THIS IS LINE2 OF NOTE2</Note>.
    I have a query like this
    SELECT XMLAGG(XMLPARSE(CONTENT LINETEXT WELLFORMED))
    FROM TAB1
    GROUP BY NOTENUM
    ORDER BY NOTENUM DESC
    Above query would return the text of all lines concatenated for each note and the first row would be the one with highest notenum value.
    My problem is that concatenation of the LINETEXT should happen in ascending order of LINENUM. Since LINENUM is not in GROUP BY clause I cannot specify it in ORDER BY.
    How can I specify to XMLAGG (for that matter any group by function) to concatenate text in a specific order.
    I hope I was able to explain my problem clear enough for somebody to help.
    thanks for all the help
    Message was edited by:
    user448703
    Message was edited by:
    user448703

    Never mind. I just found out that XMLAGG function has the option to specify ORDER BY. I think that will work.

  • Group by function use in sql

    I want to get an output using group by function of there is no data in the table to display a particular value
    for eg:
    SELECT TRUNC(updated_date) DATE1 , COUNT(1) COUNT FROM table
    where TRUNC(updated_date) >=TRUNC(SYSDATE-18) AND TRUNC(updated_date) <=TRUNC(SYSDATE)
    GROUP BY TRUNC(updated_date)
    ORDER BY TRUNC(updated_date) DESC;
    DATE1 COUNT
    6/16/2012 14208
    6/15/2012 307825
    6/14/2012 172988
    6/6/2012 138790
    6/5/2012 167562
    6/4/2012 51870
    6/2/2012 130582
    6/1/2012 239806
    But i need the missed out date i.e 6/3/2012 - 0, 6/7/2012 - 0 to be displayed since there is no data on the repective dates.

    Hi,
    You can only display things that are in a table (or result set, but from now on, I'll just say table), or that can be derived from a table. If you want to display dates that are not in your table, then you have to get them from another table, or derive them from some table.
    Some people actually keep tables of possible dates for queries like this. In this case, all you need is a table of the last 19 dates, ending with today. That's easy to derive from dual:
    WITH     all_dates     AS
         SELECT     TRUNC (SYSDATE)     - LEVEL     AS date1
         ,     TRUNC (SYSDATE) + 1 - LEVEL     AS date2
         FROM     dual
         CONNECT BY     LEVEL <= 19
    SELECT    a.date1
    ,        COUNT (x.updated_date)     AS count
    FROM                all_dates     a
    LEFT OUTER JOIN    table_x     x  ON     x.updated_date     >= a.date1
                                AND     x.updated_date     <  a.date2
    GROUP BY  a.date1
    ORDER BY  a.date1
    ;If you'd care to post CREATE TABLE and INSERT statements for some sample data, and the results you want from that data, then I could test this.

  • Count(*) with group by max(date)

    SQL> select xdesc,xcust,xdate from coba1 order by xdesc,xcust,xdate;
    XDESC XCUST XDATE
    RUB-A 11026 01-JAN-06
    RUB-A 11026 05-JAN-06
    RUB-A 11026 08-JAN-06
    RUB-A 11027 10-JAN-06
    RUB-B 11026 02-JAN-06
    RUB-B 11026 08-JAN-06
    RUB-B 11026 09-JAN-06
    RUB-C 11027 08-JAN-06
    I want to make sql that result :
    XDESC     COUNT(*)
    RUB-A     2
    RUB-B 1
    RUB-C 1
    Criteria : GROUPING: XDESC XCUST AND MAX(DATE)
    bellow mark *** that was selected in count.
    XDESC XCUST XDATE
    RUB-A 11026 01-JAN-06
    RUB-A 11026 05-JAN-06
    RUB-A 11026 08-JAN-06 ***
    RUB-A 11027 10-JAN-06 ***
    ---------------------------------------------------------COUNT RUB-A = 2
    RUB-B 11026 02-JAN-06
    RUB-B 11026 08-JAN-06
    RUB-B 11026 09-JAN-06 ***
    ---------------------------------------------------------COUNT RUB-B = 1
    RUB-C 11027 08-JAN-06 ***
    --------------------------------------------------------COUNT RUB-C = 1
    Can Anybody help ?
    I tried :
    select xdesc,max(xdate),count(max(xdate)) from coba1 group by xdesc
    ERROR at line 1:
    ORA-00937: not a single-group group function
    Thank

    This one is duplicate. see the following link
    Count(*) with group by max(date)
    Thanks

  • Win SDK function conflict with CVI library function

    I do not have  SDK_CONFLICT_PRIORITY defined.  Is this new to CVI 2009?
    The following code gives me an error  "11, 58   Too many arguments to `CVI_WriteFile'."
    #include <windows.h> 
    #include <formatio.h>  
    void function (void) {
        HANDLE hHandle = INVALID_HANDLE_VALUE;
        char buffer [1000] = {'\0'};
        DWORD dwWriteCount;
      if (!WriteFile (hHandle, buffer, 5, &dwWriteCount, NULL)) {
    I have included  <windows.h>   before   <formatio.h>  but CVI still wants to use the formatio version of WriteFile - it appears to have been renamed   CVI_WriteFile  ?!?!?
    If I eliminate the #include <formatio.h>  it compiles OK.
    Message Edited by menchar on 03-06-2010 04:00 PM

    Well, the complete source for formatio.h I reported before is this one:
    #ifdef _NI_mswin32_
    extern int CVIFUNC      cviprefix(CloseFile)(int handle);
    extern int CVIFUNC      cviprefix(OpenFile)(const char *filename,int rd_wrt, int action, int bin_ascii);
    extern int CVIFUNC      cviprefix(ReadFile)(int handle, char *buf, int count);
    extern int CVIFUNC      cviprefix(WriteFile)(int handle, const char *buf, int count);
    extern int CVIFUNC      cviprefix(SetCommitMode)(int commit);
    #define CloseFile       cviprefix(CloseFile)
    #define OpenFile        cviprefix(OpenFile)
    #define ReadFile        cviprefix(ReadFile)
    #define WriteFile       cviprefix(WriteFile)
    #define SetCommitMode   cviprefix(SetCommitMode)
    #else
    In the header this warning is present:
    /* This header must be included after any Windows SDK header or any header */
    /* that directly or indirectly includes a Windows SDK header.              */
    /* Some of the function names conflict with Windows SDK functions.         */
    As far as I can understand (but I'm not an expert on these very technical and tricky aspects of C) first of all CVI functions are renamed CVI_xxx, after it a call to WriteFile or any other function in that group is defined to be translated to CVI_WriteFile, so when you call WriteFile the preprocessor actually translates it in the CVI version of the function and SDK one is superseded.
    My understandment is that if you undefine WriteFile, you can actually use both functions if you want: native CVI one by calling CVI_WriteFile and SDK one by simply calling WriteFile.
    ...or I can be missing some other hint, which can surely be possible!
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Aggregate fuction with group by clause

    Hello,
    Following is assignment is given but i dont get correct output 
    so please i am request to all of us write code to solve my problem.
    There can be multiple records for one customer in VBAK tables with different combinations.
    Considering that we do not need details of each sales order,
    use Aggregate functions with GROUP BY clause in SELECT to read the fields.
    <garbled code removed>
    Moderator Message: Please paste the relevant portions of the code
    Edited by: Suhas Saha on Nov 18, 2011 1:48 PM

    So if you need not want all the repeated records, then you select all the values to an Internal table,
    and declare an internal table of same type and Usee COLLECT
    for ex:
    itab1 type  <xxxx>.
    wa_itba like line of itab1.
    itab2 type  <xxxx>. "<-This should be same type of above.
    select * from ..... into table itab1.
    and now...
    loop at itab1 into wa_itab.
    collect wa_itab1 into itab2.
    endloop.
    then you will get your desired result..

Maybe you are looking for

  • Bug in photo library : all in low res (res of the viewer)

    I have a strange bug, after having installed an app (Iris photo suite). All my pics are now viewed in low res in the iphone (the res of the thumbnail !!). and impossible to delete the pics of the photo library. I tried to shut of and restart the ipho

  • Missing Live Video From Evanescence

    Greetings, I just purchased Evanescence's album Fallen. During the download of the album it showed that it was downloading the video of the band performing Bring Me Back To Life live. I cannot locate this video anywhere. I do not have a video iPod, b

  • How to Transfer Objects from one Package to another?

    Hi, I have Objects(Form Layouts,ABAP Programs....ect) in Package. Is there a particular Transaction that could be used to move these objects to another Package. Thanks Kishan

  • 3D Path

    Yes, searched, RTFM, and googled, but can't find the right answer. I have made a 'window' with a cross in the middle (see pic). I can make text follow a path, but only in 2D. I want it to come out of one window frame and go through another several ti

  • Error in the display of values

    Hi friends, I have a problem in the display of values in my report, It displays ### in some columns. But my table has numerical values in it. But it doesn't display it. Why is it so? Help me out.