Help in group by function

Hi All
very simple one but i just confused by it . i just want to display the rows in group by function .
example
SQL> select user_full_name,last_login_date,email_address from comit_user group by company_code
its giving an error .
could some one please help me in this .
thanks in advance .

Hi there,
Group by is used with group functions such as SUM, AVG, MAX, MIN, etc
eg. select job, sum(sal) from emp group by job;
JOB SUM(SAL)
ANALYST 6000
CLERK 4150
MANAGER 8275
PRESIDENT 5000
SALESMAN 5600
In your query, it looks like you need to use ORDER BY instead
select user_full_name,last_login_date,email_address from comit_user
ORDER BY company_code
Regards,
John

Similar Messages

  • 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.

  • Help in group by query

    Hi,
    Please help me in the following query.
    SELECT
    a.bcast_id ,
    a.bcast_file_nm ,
    a.clickthru_url_cd ,
    a.list_id ,
    a.prs_id ,
    a.resp_cd ,
    a.run_seq ,
    COUNT(a.resp_cd) ,
    c.src_grp_cd ,
    b.site_cd
    FROM
    gca_cbx_response_test a ,
    gca_program_run_hist b ,
    campaign_master c
    WHERE
    a.list_id=b.list_id
    AND
    a.run_seq=b.campaign_run_seq
    AND
    b.campaign_cd=c.campaign_cd
    GROUP BY
    a.bcast_id ,
    a.bcast_file_nm ,
    a.clickthru_url_cd ,
    a.list_id ,
    a.prs_id ,
    a.resp_cd ,
    a.run_seq ,
    c.src_grp_cd ,
    b.site_cd
    HAVING
    a.resp_ts
    BETWEEN
    to_date('04-AUG-2005 00:01:32','DD-MON-YYYY HH24:MI:SS')
    AND
    to_date('04-AUG-2005 00:01:32','DD-MON-YYYY HH24:MI:SS');
    But the following group by query is throwing error that a.resp_ts is not a group by function.
    But i don't want to add a.resp_ts in group by clause.
    Please help me in this query.
    Thanks,
    Dilip

    How about:
    SELECT a.bcast_id ,
           a.bcast_file_nm ,
           a.clickthru_url_cd ,
           a.list_id ,
           a.prs_id ,
           a.resp_cd ,
           a.run_seq ,
           COUNT(a.resp_cd) ,
           c.src_grp_cd ,
           b.site_cd
    FROM   gca_cbx_response_test a ,
           gca_program_run_hist b ,
           campaign_master c
    WHERE  a.list_id=b.list_id
    AND    a.run_seq=b.campaign_run_seq
    AND    b.campaign_cd=c.campaign_cd
    AND    a.resp_ts BETWEEN to_date('04-AUG-2005 00:01:32','DD-MON-YYYY HH24:MI:SS')
                     AND to_date('04-AUG-2005 00:01:32','DD-MON-YYYY HH24:MI:SS');
    GROUP BY a.bcast_id ,
             a.bcast_file_nm ,
             a.clickthru_url_cd ,
             a.list_id ,
             a.prs_id ,
             a.resp_cd ,
             a.run_seq ,
             c.src_grp_cd ,
             b.site_cd;

  • How to Use a Group by Function

    Hi Gurus,
    I have Requirment where i need to use the group by function to one column
    below is my query , can anyone help how to use the group by for the column OCCASIONALS_QT_STATUS.
    below is giving me the error not a group by expression
    select distinct source_id,OCCASIONALS_QT_STATUS,
    (SELECT sum(head_count)
    FROM gen_dcsf_occasionals_count
    where OCCASIONALS_QT_STATUS = 'QTS'
    and source_id = gdoc.source_id
    ) OccasionalsQTS,
    (SELECT sum(head_count)
    FROM gen_dcsf_occasionals_count
    where
    OCCASIONALS_QT_STATUS = 'NOTQTS'
    and source_id = gdoc.source_id
    ) OccasionalsNOTQTS,
    (SELECT sum(head_count)
    FROM gen_dcsf_occasionals_count
    where
    OCCASIONALS_QT_STATUS = 'NTKNWN'
    and source_id = gdoc.source_id
    ) OccasionalsNOTKNWN
    from gen_dcsf_occasionals_count gdoc group by OCCASIONALS_QT_STATUS;
    any inputs on this is highly appreciable
    Thanks in advance

    909577 wrote:
    Hi Gurus,
    I have Requirment where i need to use the group by function to one column
    below is my query , can anyone help how to use the group by for the column OCCASIONALS_QT_STATUS.
    below is giving me the error not a group by expression
    select distinct source_id,OCCASIONALS_QT_STATUS,
    (SELECT sum(head_count)
    FROM gen_dcsf_occasionals_count
    where OCCASIONALS_QT_STATUS = 'QTS'
    and source_id = gdoc.source_id
    ) OccasionalsQTS,
    (SELECT sum(head_count)
    FROM gen_dcsf_occasionals_count
    where
    OCCASIONALS_QT_STATUS = 'NOTQTS'
    and source_id = gdoc.source_id
    ) OccasionalsNOTQTS,
    (SELECT sum(head_count)
    FROM gen_dcsf_occasionals_count
    where
    OCCASIONALS_QT_STATUS = 'NTKNWN'
    and source_id = gdoc.source_id
    ) OccasionalsNOTKNWN
    from gen_dcsf_occasionals_count gdoc group by OCCASIONALS_QT_STATUS;
    any inputs on this is highly appreciable
    Thanks in advanceFor your own sanity, you should format your code to make it more readable
    For the sanity of those from whom you seek help, you should preserve that formatting with the code tags:
    select
         distinct source_id,
         OCCASIONALS_QT_STATUS,
         (SELECT
               sum(head_count)
          FROM
               gen_dcsf_occasionals_count
          where
               OCCASIONALS_QT_STATUS = 'QTS'   and
               source_id = gdoc.source_id
         ) OccasionalsQTS,
         (SELECT
              sum(head_count)
         FROM
              gen_dcsf_occasionals_count
         where
              OCCASIONALS_QT_STATUS = 'NOTQTS' and
              source_id = gdoc.source_id
         ) OccasionalsNOTQTS,
         (SELECT
              sum(head_count)
         FROM
              gen_dcsf_occasionals_count
         where
              OCCASIONALS_QT_STATUS = 'NTKNWN' and
              source_id = gdoc.source_id
         ) OccasionalsNOTKNWN
    from
         gen_dcsf_occasionals_count gdoc
    group by
         OCCASIONALS_QT_STATUS;

  • Group by function in a measure object

    Hi All,
        I am trying to create a measure in universe which is the sum of ticket amount group by country. like,
    sum(Payments.Ticket_Amount) group by country name. When i place this measure in a report group footer it should display the sum to that particular group. But it is not working.
    Could anybody help me how to write a group by function to create a measure.
    Thanks,
    swati.

    Hi swati.
    You don't need to write the GROUP BY statement at the universe level.
    The universe knows that aggregate functions require group by statements and will group the aggregate measure objects by whatever dimension objects are included in the query. If you have a measure object that is not based on an aggregate but has a projection of Sum, it will only be aggregated at the report level once the data has been returned by the query.
    Measure: sum(sales_fact.value)
    Measure: sales_fact.price
    Dimension: country_dim.country
    This would generate SQL along the lines of:
    SELECT sales_fact.price, country_dim.country, sum(sales_fact.value)
    FROM sales_fact, country_dim
    WHERE sales_fact.country_key = country_dim.country_key
    GROUP BY sales_fact.price, country_dim.country
    Hope that clears it up for you.
    Regards,
    Mark

  • 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.

  • 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
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------

  • Help in using listagg function for more than 8000 char.

    Hi Friends,
    Need you urgent help in using listagg function for more than 8000 char.
    I did the below sample SQL and in "e_orig" and "d_orig" for upto 4000 char it is working fine but I have to use it for more than 8000 char. and it is giving error,
    I checked the listagg function is having limitation of 4000 char.
    I tried but I am unable to achive this. Can someone provide me a sample example to achive this
    select d.dname,d.loc,e.hiredate
    ,listagg(e.ename,',' ) within group (order by e.deptno) over (partition by e.deptno) as e_orig
    ,listagg(e.ename, ',') within group (order by e.sal) over (partition by e.deptno) as d_orig
    from emp e, dept d
    where e.deptno=d.deptno;[ This is my first post, I gone through the guideline for posting a post , and try to go according to that ( I have not pasted here create table and insert as I have used basic table emp, dept for example), please let me know if still I should give this, I will take care from my next post ]
    Thanks in advance

    Interesting, I didn't know you could do that, but...
    BluShadow wrote:
    You could write some PL/SQL code that does it all for you, but that would involve loops and would be slow.Well, objects are written in PL/SQL aren't they? And presumably there'll be implicit looping too? So it's not at all obvious that this method will be faster than doing the joining in PL/SQL in memory. The only way to find out is to benchmark them - so I have done that.
    I noticed that OP's ref cursor actually only ever retrieves a single record for a bound department number, so I decided the best thing would be to test using a procedure that passes an output string back. I selected all (109) employees and put spaces in to ensure above 4000 characters. I also noticed that as he is using PL/SQL he probably can use a VARCHAR2 type, but just not ListAgg in the query, so I wrote short procedures as follows:
    SimpleAggChr     - bulk collect and array processing, VARCHAR2 output
    ClobAggPrc     - the custom aggregation method, CLOB output
    SimpleAggClob     - bulk collect and array processing, CLOB output
    I then wrote a driving script that calls them in the order above and times each call (I like benchmarking so I have my own timing object to make it easy). I then print the lengths for checking, and my object writes the timings to my output table. Running a few times I got varying results, but generally it looks like there isn't a lot to choose between them for performance.
    Here's the procedure code:
    CREATE OR REPLACE TYPE char100_list_type AS TABLE OF VARCHAR2(100)
    CREATE OR REPLACE PROCEDURE SimpleAggChr (x_out OUT VARCHAR2) IS
      l_enames     char100_list_type;
    BEGIN
      SELECT first_name || '                                        ' || last_name
        BULK COLLECT INTO l_enames
        FROM employees
       ORDER BY salary;
      FOR i IN 1..l_enames.COUNT LOOP
        x_out := x_out || l_enames(i) || ',';
      END LOOP;
    END SimpleAggChr;
    CREATE OR REPLACE PROCEDURE SimpleAggClob (x_out OUT CLOB) IS
      l_enames     char100_list_type;
    BEGIN
      SELECT first_name || '                                        ' || last_name
        BULK COLLECT INTO l_enames
        FROM employees
       ORDER BY salary;
      FOR i IN 1..l_enames.COUNT LOOP
        x_out := x_out || l_enames(i) || ',';
      END LOOP;
    END SimpleAggClob;
    SHO ERR
    PROMPT ClobAggPrc
    CREATE OR REPLACE PROCEDURE ClobAggPrc (x_out OUT CLOB) IS
    BEGIN
      SELECT clobagg(first_name || '                                        ' || last_name || ',')
        INTO x_out
        FROM employees
       ORDER BY salary;
    END ClobAggPrc;
    SHO ERRand the driving script:
    SET SERVEROUTPUT ON
    SET TIMING ON
    DECLARE
      l_enames_c1     CLOB;
      l_enames_c2     CLOB;
      l_enames_v     VARCHAR2(32767);
      l_timer     timer_set_type := timer_set_type ('Aggregation');
    BEGIN
      Utils.g_id := 'Aggregation';
      SimpleAggChr (l_enames_v);
      l_timer.Increment_Time ('SimpleAggChr');
      ClobAggPrc (l_enames_c1);
      l_timer.Increment_Time ('ClobAggPrc');
      SimpleAggClob (l_enames_c2);
      l_timer.Increment_Time ('SimpleAggClob');
      DBMS_Output.Put_Line ('SimpleAggChr returned string of length ' || Length (l_enames_v));
      DBMS_Output.Put_Line ('ClobAggPrc returned string of length ' || Length (l_enames_c1));
      DBMS_Output.Put_Line ('SimpleAggClob returned string of length ' || Length (l_enames_c2));
      l_timer.Write_Times;
    END;
    SET TIMING OFF
    SET LINES 150
    SET PAGES 1000
    COLUMN id FORMAT A30
    COLUMN line_text FORMAT A120
    SELECT line_text
      FROM output_log
    WHERE id = 'Aggregation'
    ORDER BY line_ind
    /and the results:
    SimpleAggChr returned string of length 5779
    ClobAggPrc returned string of length 5779
    SimpleAggClob returned string of length 5779
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:27.05
    LINE_TEXT
    Timer Set: Aggregation, constructed at 03 Nov 2011 16:27:07, written at 16:27:35
    ================================================================================
    [Timer timed: Elapsed (per call): 0.02 (0.000016), CPU (per call): 0.01 (0.000010), calls: 1000, '***' denotes corrected
    line below]
    Timer              Elapsed          CPU          Calls        Ela/Call        CPU/Call
    SimpleAggChr          9.84         0.36              1         9.84400         0.36000
    ClobAggPrc            9.37         0.32              1         9.37400         0.32000
    SimpleAggClob         8.25         0.22              1         8.25000         0.22000
    (Other)               0.00         0.00              1         0.00000         0.00000
    Total                27.47         0.90              4         6.86700         0.22500
    13 rows selected.

  • In my opinion, I think the rolling function of Muse need to add the group status function and group!

    In my opinion,
    I think the rolling function of Muse need to add the group status function and group!
    Because when the processing of many things, but the effect is the same,
    but to repeat many times, it is necessary to group similar function of PS.

    I learned how to install the 9.1.3 upgrade by renaming my app, and that works fine. Logic is now recognized in About My Mac as a 64 bit app, which is where I started. Thanks for your help.
    Now I have to figure out how to get my Novation to work through Automap in some way that I can finally get mixer functions. I'll repost the second part of this if I'm still having a headscratcher about it tomorrow.

  • 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.

  • Need help in group left report

    i need help in group left report
    i am making group left report in which all group data on top is repeating as many time as detail record is .
    for axampel
    if
    group record:
    fielda fieldb field c
    fielda fieldb field c
    fielda fieldb field c
    fielda fieldb field c
    detail record :
    fieldd fielde feildf
    fieldd fielde feild
    fieldd fielde feild
    fieldd fielde feildf
    how i can show group record on top once and on each group record show detail record belong to master record.
    plz help me
    A.R

    I think you Should go for Group above report...
    and if you want group left only and also want to display master once then
    put all master fields above but yeah take care of it's master repeting frame
    it should not change...
    and if you want i can send you an example...
    Enjoy Oracle...

  • Need some help with a remove function

    Design and code a program that will maintain a list of product names. Use a String type to represent the product name and an array of strings to implement the list. Your program must implement the following methods:
    Add a product to the list
    Remove a product from the list
    Display then entire list
    Find out if a particular product is on the list.
    You need to create a command command loop with a menu() function. The program must continue asking for input until the user stops.
    This is the assignment and this is what I have so far. I need some help writing the remove function.
    Thanks
    * Title: SimpleSearchableList.java
    * Description: this example will show a reasonably efficient and
    * simple algorithm for rearranging the value in an array
    * in ascending order.
    public class SimpleSearchableList {
         private static String[] List = new String[25]; //These variables (field variables)
         private static int Size; //are common to the entire class, but unavailable
         //except to the methods of the class...
         public static void main(String[] args)
              String Cmd;
              for(;;) {
                   Menu();
                   System.out.print("Command: ");
                   Cmd = SimpleIO.inputString();
                   if(Cmd.equals("Quit"))
                        break;
                   else if(Cmd.equals("Fill"))
                        FillList();
                   else if(Cmd.equals("Search"))
                        SearchList();
                   else if(Cmd.equals("Show"))
                        ShowList();
                   else if(Cmd.equals("Remove"))
                        Remove();
         //Tells you what you can do...
         public static void Menu()
              System.out.println("Choices..................................");
              System.out.println("\tFill to Enter Product");
              System.out.println("\tShow to Show Products");
              System.out.println("\tSearch to Search for Product");
              System.out.println("\tRemove a Product");
              System.out.println("\tQuit");
              System.out.println(".........................................");
         //This method will allow the user to fill an array with values...
         public static void FillList()
              int Count;
              System.out.println("Type Stop to Stop");
              for(Count = 0 ; Count < List.length ; Count++)
                   System.out.print("Enter Product: ");
                   List[Count] = SimpleIO.inputString();
                   if(List[Count].equals("Stop"))
                        break;
              Size = Count;
         //This method will rearrange the values in the array so that
         // go from smallest to largest (ascending) order...
         public static void SearchList()
              String KeyValue;
              boolean NotFoundFlag;
              int Z;
              System.out.println("Enter Product Names Below, Stop To Quit");
              while(true)
                   System.out.print("Enter: ");
                   KeyValue = SimpleIO.inputString();
                   if(KeyValue.equals("Stop")) //Note the use of a method for testing
                        break; // for equality...
                   NotFoundFlag = true; //We'll assume the negative
                   for(Z = 0 ; Z < Size ; Z++)
                        if(List[Z].equals(KeyValue)) {
                             NotFoundFlag = false; //If we fine the name, we'll reset the flag
              System.out.println(List[Z] + " was found");
                   if(NotFoundFlag)
                        System.out.println(KeyValue + " was not found");     
         //This method will display the contents of the array...
         public static void ShowList()
              int Z;
              for(Z = 0 ; Z < Size ; Z++)
                   System.out.println("Product " + (Z+1) + " = " + List[Z]);
         public static void Remove()
    }

    I need help removing a product from the arrayYes. So what's your problem?
    "Doctor, I need help."
    "What's wrong?"
    "I need help!"
    Great.
    By the way, you can't remove anything from an array. You'll have to copy the remaining stuff into a new one, or maybe maintain a list of "empty" slots. Or null the slots and handle that. The first way will be the easiest though.

  • Help needed with printf function!!!!

    public class Try
    {public static void main (String[] args)
    {int a;
    String b;
    a = 000002;
    b = "JSmith";
    System.out.printf(b + "%d", a);
    }}I need a help with the printf function.
    The result of this small excercise that I just made is:
    Jsmith2
    How do I make it so that the zeros is also displayed? (using the printf)
    I want it to look like this: Jsmith000002
    Thank you in advance

    TrySystem.out.printf(b + "%06d", a);(I don't have a compiler here so I haven't tested this).
    The "6" is the width - the minimum number of characters that will be
    printed and the "0" (it's a zero) is a flag indicating that the output should
    be padded with zeros.
    You should also note that the value of a is two. It doesn't matter whether
    you say a=2; or a=0002; - a is still just plain two.

  • To fetch data using group by function

    Hi Guys,
    I am having a table where it holds data with value with zero in one of the column and i need to fetch the records from the table using group by function but to display all the records if zero occurs in my table
    for eg
    table1
    id,customer_name,country
    0     sam     aus
    1     peter     ind
    1 peter    ind
    0 samy     us
    0 rayan     nz
    if i use select count(*),id from table1 group by id
    i will get
    count(*),id
    3-0
    1-2
    but wat i need is like below
    0     sam     aus
    0 samy     us
    0 rayan     nz
    2 peter ind
    whenever zero is occurring i need to display all the records but group by should work for non zero records

    The simplest way would be to have two queries and UNION them together. For example:
    WITH test_data AS
    ( SELECT 0 AS id, 'sam' AS customer_name, 'aus' AS country FROM DUAL UNION ALL
      SELECT 1 AS id, 'peter' AS customer_name, 'ind' AS country FROM DUAL UNION ALL
      SELECT 1 AS id, 'peter' AS customer_name, 'ind' AS country FROM DUAL UNION ALL
      SELECT 0 AS id, 'samy' AS customer_name, 'us' AS country FROM DUAL UNION ALL
      SELECT 0 AS id, 'rayan' AS customer_name, 'nz' AS country FROM DUAL
    SELECT cnt
         , customer_name
         , country
    FROM   ( SELECT id
                  , customer_name
                  , country
                  , COUNT(*) OVER (PARTITION BY id) AS cnt
                  , ROW_NUMBER() OVER (PARTITION BY id ORDER BY id) rn
             FROM   test_data
             WHERE  id != 0
    WHERE  rn = 1    
    UNION
    SELECT id
         , customer_name
         , country
    FROM   test_data
    WHERE  id = 0
    This gives the following results:
           CNT CUSTO COU
             0 rayan nz
             0 sam   aus
             0 samy  us
             2 peter ind

Maybe you are looking for

  • My Safari 5.1 Browser consistently freezes on my iMac with Intel. Help?

    I need help. I am getting frustrated using my Safari browser. It keeps crashing on me - or rather - freezing up. I have re-installed the software, checked for updates. Everything is up to date. Is there anybody who can offer me some help?

  • Purchasing a MacPro, worried about Leapard upgrade

    Ok, so longterm PC user, finally getting my first Mac. Pretty sure I want the MacBook Pro 17 inch. Mobility + Power. My worry is this: Leapard looks amazing, and somewhat demanding. Being that it comes out in October (I believe), am I better off wait

  • OS 10.6.8 finder blinking

    My finder blinks every 60 seconds. All desktop icons briefly dissapear. Open folders randomly close. I have restarted, Reset the PRAM and SMC. I am running OS 10.6.8, Model Name:          iMac   Model Identifier:          iMac10,1   Processor Name:  

  • Sample Scenarios

    Hi,    Can someone help me in getting some sample scenarios using Wait,Switch and Exception handling in BPM

  • When i try to down load the updated version of flash player it will only save and not run...please help

    Can not down load up date for flash player..I tried removing my original flash player and this did not work...and now i have no flask player! A firefox window opens for down load and only reads "save" or "cancel" it does not have a "RUN" button. When