Error in nested group function used with column name.

Hi Team,
If i used nested group function with column name its not working. Could you please any one suggest me.
How to use it.
Regards,
Venkat.
Please find Spool ........
SQL> select user_name,max(max(CNT)) from (select USER_NAME,count(*) CNT from v$open_cursor group by USER_NAME)
2 group by user_name,CNT;
select user_name,max(max(CNT)) from (select USER_NAME,count(*) CNT from v$open_cursor group by USER_NAME)
ERROR at line 1:
ORA-00937: not a single-group group function
SQL> select max(max(CNT)) from(select USER_NAME,count(*) CNT from v$open_cursor group by USER_NAME)
2 group by user_name;
MAX(MAX(CNT))
605

Venkat wrote:
Hi Sayan
Its giving output like below, but not given maximum CNT.
SQL> select user_name,max(CNT)from (select USER_NAME,count(*) CNT from v$open_cursor group by USER_NAME)
2 group by user_name;
USER_NAME MAX(CNT)
BANES_LERG 6
VENE_USER 8
USER3 339
DBUS 106
VEL_USER 37
SYS 597
6 rows selected.Check it - Re: Error in nested group function used with column name.
and previous post

Similar Messages

  • Nested Group Function without Group By Problem

    Hey everyone,
    I have 3 tables as below:
    TABLES
    ITEM (Item_no, Item_price, desc)
    DeliveryItem (delivery_no, item_no, quantity)
    Delivery (delivery_no, delivery_date)
    SELECT desc, MAX(SUM(quantity)) FROM DeliveryItem, Item, Delivery WHERE Item.item_no = DeliveryItem.item_no AND Delivery.delivery_no = deliveryitem.delivery_no;
    And I'm trying to output description of most delivered item but I got an error like SQL Error: ORA-00978: nested group function without GROUP BY. Could you help me to fix my code?
    Thanx

    Hi,
    DESC is not a good column name; you could get errors if the parser thinks it means DESCending. I used DESCRIPTION instead, below.
    I think the best way is to do the SUM in a sub-query, lkike this:
    WITH     got_r_num     AS
         SELECT       item_no
         ,       SUM (quantity)     AS total_quantity
         ,       RANK () OVER (ORDER BY  SUM (quantity) DESC)     AS r_num
         FROM       deliveryitem
         GROUP BY  item_no
    SELECT     i.description
    ,     r.total_quantity
    FROM     got_r_num     r
    JOIN     item          i     ON     r.item_no     = i.item_no
    WHERE     r.r_num     = 1
    ;If you want to do it without a sub-query:
    SELECT       MIN (i.description) KEEP (DENSE_RANK LAST ORDER BY SUM (di.quantity)
                        AS description
    ,       MAX (SUM (quantity))     AS total_quantity
    FROM       deliveryitem     di
    JOIN       item          i     ON     d1.item_no     = i.tiem_no
    GROUP BY  i.description
    ;If you do nested aggegate functions, then every column in the SELECT clause must be an aggregate applied to either
    (a) another aggregate, or
    (b) one of the GROUP BY expressions.
    That's why you got the ORA-00937 error.
    This second approach will only display one row of output, so If there is a tie for the item with the greatest total_quantity, only one description will be shown. The RANK method will show all items that had the highest total_quantity.
    It looks like the delivery table plays no role in this problem, but it there's some reason for including it, you can join it tpo either query above.
    Of course, unless you post test copies of your tables (CREATE TABLE and INSERT statements) I cn't test anything.
    Edited by: Frank Kulash on Nov 6, 2010 10:57 AM

  • Nested group function

    Hello all,
    How can I use a nested group function in a select statement?
    For example: select sum(count(id), column a, column b from table_name group by???
    Thanks in advance!

    select sum(CNT) column_a, column_b
           from  (select count(id), column_a, column_b from table_name
                            group by column_a, column_b)
    group by column_a, column_b

  • Nested group function without group xmlagg

    I am getting nested group function without group by xmlagg when using the xmlagg function inside another xmlagg function. Find the table structure and sample data here,
    CREATE TABLE "TEST_TABLE"
       ("KEY" NUMBER(20,0),
        "NAME" VARCHAR2(50 ),
        "DESCRIPTION" VARCHAR2(100 )
       Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (1,'sam','desc1');
       Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (2,'max','desc2');
       Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (3,'peter',null);
       Insert into TEST_TABLE (KEY,NAME,DESCRIPTION) values (4,'andrew',null);
    select
            XMLSerialize(document
            xmlelement("root",
             xmlagg(
               xmlelement("emp"          
               , xmlforest(Key as "ID")          
               , xmlforest(name as "ename")
               , xmlelement("Descriptions", 
               xmlagg(
                  xmlforest(description as "Desc")
           ) as clob indent
           ) as t   
          from test_table;Then i removed the xmlagg function from the above select query and used xmlelement instead
      select
            XMLSerialize(document
            xmlelement("root",
             xmlagg(
               xmlelement("emp"          
               , xmlforest(Key as "ID")          
               , xmlforest(name as "ename")
               , xmlelement("Descriptions",            
                  xmlforest(description as "Desc")
           ) as clob indent
           ) as t   
          from test_table;This is working fine, but xml created with empty elements for Descriptions element for key 3 and 4 which has null values. I need don't need Descriptions element in the xml when it has null value. Please help me to resolve this.

    You can do it with a correlated subquery :
    SQL> select xmlserialize(document
      2           xmlelement("root",
      3             xmlagg(
      4               xmlelement("emp"
      5               , xmlforest(
      6                   t.key as "ID"
      7                 , t.name as "ename"
      8                 , (
      9                     select xmlagg(
    10                              xmlelement("Desc", d.description)
    11                              order by d.description -- if necessary
    12                            )
    13                     from test_desc d
    14                     where d.key = t.key
    15                   ) as "Descriptions"
    16                 )
    17               )
    18             )
    19           ) as clob indent
    20         )
    21  from test_table t;
    XMLSERIALIZE(DOCUMENTXMLELEMEN
    <root>
      <emp>
        <ID>1</ID>
        <ename>sam</ename>
        <Descriptions>
          <Desc>desc1_1</Desc>
          <Desc>desc1_2</Desc>
          <Desc>desc1_3</Desc>
        </Descriptions>
      </emp>
      <emp>
        <ID>2</ID>
        <ename>max</ename>
        <Descriptions>
          <Desc>desc2_1</Desc>
          <Desc>desc2_2</Desc>
          <Desc>desc2_3</Desc>
        </Descriptions>
      </emp>
      <emp>
        <ID>3</ID>
        <ename>peter</ename>
      </emp>
      <emp>
        <ID>4</ID>
        <ename>andrew</ename>
      </emp>
    </root>
    Or an OUTER JOIN + GROUP-BY :
    select xmlserialize(document
             xmlelement("root",
               xmlagg(
                 xmlelement("emp"          
                 , xmlforest(
                     t.key as "ID"
                   , t.name as "ename"
                   , xmlagg(
                       xmlforest(d.description as "Desc")
                       order by d.description -- if necessary
                     ) as "Descriptions"
             ) as clob indent
    from test_table t
         left outer join test_desc d on d.key = t.key
    group by t.key
           , t.name
    ;Edited by: odie_63 on 11 juil. 2012 14:54 - added 2nd option

  • APEX 4.0 "Use Generic Column Names" not working

    Hi,
    I have a report which is a SQL query (PL/SQL function body returning SQL query) in APEX 4.0. For this region i have selected the option "Use Generic Column Names (parse query at run time only)".
    For some reason when I run the page the browser just shows the error "The requested URL /apex/f was not found on this server". This happens only for the region type "SQL query (PL/SQL function body returning SQL query)" . If I choose the report region as SQL query and select the option "Use Generic Column Names (parse query at run time only)" That works fine. This happens only in APEX 4. Is it an apex 4 bug or am I missing something?
    Thanks
    Sashika.

    Hi,
    Just managed to get it running. The Apex 4.0 SQL query (PL/SQL function returning SQL) works just fine. I had a small error in the query itself. In the PL/SQL function I had a referenced page item whose value in the initial run is set to null which is making the fuzz. Just adding an NVL resolved the problem.

  • ERROR ITMS-9000 "The bundle uses a bundle name or display name..." when uploading to iTunesConnect

    I'm receiving the error "ERROR ITMS-9000 "The bundle uses a bundle name or display name associated with an Apple app." when uploading to iTunesConnect.
    Version 1.0 or our app is currently on the App store, an I'm trying to upload a version 1.1.
    I'm trying to change the name of the app from "Augsburg Now" to "Augsburg Gallery".
    I changed the name in the App ID on developer.apple.com to "Augsburg Gallery, but left the ID as edu.augsburg.augsburgnow
    I generated new Development and Distribution provisioning profiles, since the App ID name had changed.
    In DPS App Builder, I changed the App name to "Gallery", and the Title (library view) in DPS App Builder to "Augsburg Gallery", and then created a new binary.
    I changed the App Name in iTunes connect to "Augsburg Gallery"
    I don't see the problem, since I left the bundle id, app id, etc. all unchanged.
    Any ideas?

    It sounds like you did everything right, Keith. I just did a similar thing recently to change my app name from "Digital Publishing Suite Tips" to "DPS Tips," so I know it's possible. In iTunes Connect, you submitted the app as a new version, not as a new app, right?
    I would try building a new app and submitting it again.

  • Bcp queryout with column name in output

    DECLARE @cmd nvarchar(1000);
    SELECT @cmd = 'bcp "SELECT ObjectID,FeatureID,ParcelID,Card,ISNULL(Units,0) as Units,ISNULL(Bed,0) as Bed,ISNULL(Bath,0) as Bath,ISNULL(Half,0) as Half,TaxYear FROM pubtables.dbo.Tax_StructureApartment" queryout "\\WDC1GISSHP1\Scripts\DataManagement\DataMaintenance\SyncDataCatalog2SDE\CAMA.txt" -T -c';
    PRINT @cmd
    exec xp_cmdshell @cmd;
    I am extracting certain fields from a large table and using bcp to output to a file.  The code above works, but the output does not have the column name (i.e. header).  How would I go about doing that ?
    Thank you.

    you need to add a query based on catalog view information_schema.columns for that
    see this example
    http://sqlblogcasts.com/blogs/madhivanan/archive/2008/10/10/export-to-excel-with-column-names.aspx
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Migrating from Sql Server tables with column name starting with integer

    hi,
    i'm trying to migrate a database from sqlserver but there are a lot of tables with column names starting with integer ex: *8420_SubsStatusPolicy*
    i want to make an offline migration so when i create the scripts these column are created with the same name.
    can we create rules, so when a column like this is going to be migrated, to append a character in front of it?
    when i use Copy to Oracle option it renames it by default to A8420_SubsStatusPolicy
    Edited by: user8999602 on Apr 20, 2012 1:05 PM

    Hi,
    Oracle doesn't allow object names to start with an integer. I'll check to see what happens during a migration about changing names as I haven't come across this before.
    Regards,
    Mike

  • Multi Row Selector using Generic Column Names (parse query at runtime only)

    Hi,
    I created a tabular report which had a multi row select in it - got the deleting working fine.
    Am now creating a second tabular report, but because of the SQL:
    select
    "ID",
    "ID" ID_DISPLAY,
    "RESNUMBER",
    "RESDESCRIPTION",
    decode(RESTYPE,'R','Right Party','W','Wrong Party'),
    decode(DMCFLAG,'Y','Yes','N','No'),
    decode(SALEFLAG,'Y','Yes','N','No')
    from "CALL_RESULTS"
    I have to select the option Use Generic Column Names (parse query at runtime only) otherwise I cannot save the form.
    My problem is I am now unable to add a multi row selector to the tabular form. If I do and run the form I get the following error - failed to parse SQL query: ORA-00904: "COL11": invalid identifier. Also when I go back and edit the form the multi row selector has been removed.
    Can anyone tell me why I can't add a row selector like I previously could?
    Regards
    Simon

    Arie,
    I added aliases and to the decode columns, and I can now add a row selector to the form without any problems.
    Thank you very much for your help.
    Regards
    Simon

  • ERROR:Cannot connect to Host: [MTW02SDEP02] with user name: [Administrator]

    Dear All,
    When I try to deploy WD application, it gives me this following error and doesn't deploy.
    com.sap.engine.deploy.manager.DeployManagerException: ERROR: Cannot connect to Host: [MTW02SDEP02] with user name: [Administrator]                     Check your login information.                     Exception is: com.sap.engine.services.jndi.persistent.exceptions.NamingException: Exception during getInitialContext operation. No server is running. [Root exception is
    Caused by: com.sap.engine.services.security.exceptions.BaseLoginException: Exception in creating new RemoteLoginContext instance.
         at com.sap.engine.services.security.remote.login.RemoteLoginContextExt.<init>(RemoteLoginContextExt.java:34)
         at com.sap.engine.services.jndi.implclient.LoginHelper.clientSideLogin(LoginHelper.java:81)
         at com.sap.engine.services.jndi.InitialContextFactoryImpl.getInitialContext(InitialContextFactoryImpl.java:355)
         ... 38 more
    Caused by: com.sap.engine.services.rmi_p4.P4ConnectionException: Possible problem: no available running server node. Check your running servers.
         at com.sap.engine.services.rmi_p4.P4ObjectBrokerClientImpl.getException(P4ObjectBrokerClientImpl.java:709)
         at com.sap.engine.services.rmi_p4.P4ObjectBrokerClientImpl.getException(P4ObjectBrokerClientImpl.java:697)
         at com.sap.engine.services.rmi_p4.Parser.newRequest(Parser.java:180)
         at com.sap.engine.services.rmi_p4.Connection.run(Connection.java:427)
         ... 1 more
    (message ID: com.sap.sdm.serverext.servertype.inqmy.extern.EngineApplOnlineDeployerImpl.checkLoginCredentials.DMEXC)
    Deployment exception : The deployment of at least one item aborted

    Hi
    Try this
    1. Is this is the remote server?
       if yes make one entry in host file under C:\WINDOWS\system32\drivers\etc
        format   :  <server ip>  <servername>
        restart NWDS
    2.If not then put the Ip address  instead of name inside Window--preference --Sap server Check.
    3. Put some different UserId and Password who has deployment rights
    Best Regards
    Satish Kumar

  • How to display single row column with nested group function

    SQL> select deptno, Max(sum(sal)) SalSum
    2 from emp
    3 group by deptno;
    select deptno, Max(sum(sal)) SalSum
    ERROR at line 1:
    ORA-00937: not a single-group group function
    Can you please the Help me to get the Max(sum(sal)) with Deptno ......

    select deptno, sum(sal) SalSum
    from emp
    group by deptno;The ablove query will give only one value for SALSUM for a department. So there is no meaning on applying MAX on this for a department..
    What are you trying to achieve?
    This?
    select max(salsum) salsm,max(deptno) keep(dense_rank first order by salsum desc) deptno
    from(
    select deptno, sum(sal) SalSum
    from emp
    group by deptno);Edited by: jeneesh on Sep 4, 2012 6:00 PM

  • Record Group functions - Problerms with a function Get_Group_Selection

    Anywone knows how to delete a record from a record group, i have this code below on the trigger KEY-DELREC, every time i delete a record this code is execute. The problem here is that i whant to delete a row in a record group but , i can't use the function Get_Group_Selection, to find the number of the row i want to delete, when i use the function Get_Group_Selection, it gives me the error FRM-41087 .
    Can aywone help me with that , it's urgent!!
    Thanks
    DECLARE
    ora_err NUMBER;
    rg_id RECORDGROUP;
    the_Rowcount NUMBER;
    gc_id1 GroupColumn;
    gc_id2 GroupColumn;
    v_art_grp_no number(3);
    v_descr VARCHAR2(20);
    v_art_grp_no2 number(3);
    v_descr2 VARCHAR2(20);
    v_ctn NUMBER := 0;
    v_row NUMBER;
    begin
    rg_id := Find_Group('REG_REPAIRS_COMPONENTS');
    the_Rowcount := Get_Group_Row_Count( rg_id );
    --** Make sure the column name specified exists in the ** record Group. */
    gc_id1 := Find_Column('REG_REPAIRS_COMPONENTS.ART_GRP_NO');
    gc_id2 := Find_Column('REG_REPAIRS_COMPONENTS.DESCR');
    FOR j IN 1..the_Rowcount LOOP
         v_ctn := Get_Group_Selection(rg_id,j);
         v_art_grp_no := Get_Group_Number_Cell(gc_id1,v_ctn);
    v_descr := GET_GROUP_CHAR_CELL(gc_id2,     v_ctn );
    if UPPER(v_descr) = UPPER(:system.cursor_value) and UPPER(v_art_grp_no) = UPPER(:repairs_components.art_grp_no) then
         Delete_Group_Row('REG_REPAIRS_COMPONENT',      v_ctn);
         delete_record;
         end if;
         END LOOP;
    end;

    Thanks for the HELP!
    But now i have an other problem that is when i invoke the when-validate item trigger it searchs the field for a value that´s is equal to value in a record group and if it finds it, it raises
    raise_form_trigger_failure and displays a messagem, it works fine but if a press the button save or back it displays the message and after if i press the default button to delete again it doesn´t work .

  • Error calling pl/sql function in target column

    Hi guys,
    I get this error when calling my function in ODI:
    Caused By: java.sql.SQLSyntaxErrorException: ORA-00904: "mySchema"."GET_ODI_DEFAULT_VALUE(1)": ongeldige ID --> 1 is an IN parameter
    while in sql developer I get a good result with following query:
    select mySchema.get_odi_default_value(1) from dual;
    In my target table for the primary key I call a sequence from mySchema and this works fine.
    I've tried the following synxtax in the mapping of my target column:
    - <%=odiRef.getObjectName( "L","GET_ODI_DEFAULT_VALUE(1)", "D" )%>
    - <%=odiRef.getObjectName( "L","GET_ODI_DEFAULT_VALUE", "D" )(1)%>
    Thanks for you advice

    iadgroe wrote:
    how to bring oracle function into ODI
    I thought for objects like sequences and functions you had to use 'odiRef.getObjectName' to get access to them.
    Am I wrong because now I'm a little confused???Hi,
    Best practices would be to use getobjectname method as this way your not hardcoding anything into the interface and you are referencing the logical object only, which means you can change the logical object later and not have to worry about changing the interfaces.

  • Error after creating a function using SE37

    Hello friends
    I have created a simple function (remote enabled).
    Syntax check says everything is ok.
    When I try to Activate, I get the following error message.
    Program SAPLZBAPI_CONFIGDNA_INSERT
    REPORT/PROGRAM statement missing, or program type is I (INCLUDE).
    The name of the function that I have created is ZBAPI_CONFIGDNA_INSERT.
    However, it is complaining about a program SAPLZBAPI_CONFIGDNA_INSERT.
    I have created BAPIS before and so I am sure that the steps I have created are ok.
    I even tried creating the same BAPI with different names and still the same problem.
    Any feedback will be greatly appreciated.
    Thanks
    Ram

    in the TOP Include the statement
    FUNCTION-POOL (<b>Name of function Group</b>).
    is missing.
    to Reach to th eexact point.
    to to attibutes tab of your FM
    double click on Program Name.
    double click on include ending with TOP.
    Declare the statement in the TOP include.
    amandeep.

  • Saving result from sp_executesql into a variable and using dynamic column name - getting error "Error converting data type varchar to numeric"

    Im getting an error when running a procedure that includes this code.
    I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql
    DECLARE @retval AS DECIMAL(12,2)
    DECLARE @MonthVal VARCHAR(20), @SpreadKeyVal INT
    DECLARE @sqlcmd AS NVARCHAR(150)
    DECLARE @paramdef NVARCHAR(150)
    SET @MonthVal = 'Month' + CAST(@MonthNumber AS VARCHAR(2) );
    SET @SpreadKeyVal = @SpreadKey; --CAST(@SpreadKey AS VARCHAR(10) );
    SET @sqlcmd = N' SELECT @retvalout = @MonthVal FROM dbo.CourseSpread WHERE CourseSpreadId = @SpreadKeyVal';
    SET @paramdef = N'@MonthVal VARCHAR(20), @SpreadKeyVal INT, @retvalout DECIMAL(12,2) OUTPUT'
    --default
    SET @retval = 0.0;
    EXECUTE sys.sp_executesql @sqlcmd,@paramdef, @MonthVal = 'Month4',@SpreadKeyVal = 1, @retvalout = @retval OUTPUT;
    SELECT @retval
    DECLARE @return_value DECIMAL(12,2)
    EXEC @return_value = [dbo].[GetSpreadValueByMonthNumber]
    @SpreadKey = 1,
    @MonthNumber = 4
    SELECT 'Return Value' = @return_value
    Msg 8114, Level 16, State 5, Line 1
    Error converting data type varchar to numeric.

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql <<
    This is so very, very wrong! A column is an attribute of an entity. The idea that you are so screwed up that you have no idea if you want
    the shoe size, the phone number or something else at run time of this entity. 
    In Software Engineering we have a principle called cohesion that says a model should do one and only one task, have one and only one entry point, and one and only one exit point. 
    Hey, on a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, your mindset is that level of sillyity and absurdity. 
    Do you know that SQL is a declarative language? This family of languages does not use local variables! 
    Now think about “month_val” and what it means. A month is a temporal unit of measurement, so this is as silly as saying “liter_val” in your code. Why did you use “sp_” on a procedure? It has special meaning in T-SQL.  
    Think about how silly this is: 
     SET @month_val = 'Month' + CAST(@month_nbr AS VARCHAR(2));
    We do not do display formatting in a query. This is a violation of at the tiered architecture principle. We have a presentation layer. But more than that, the INTERVAL temporal data type is a {year-month} and never just a month. This is fundamental. 
    We need to see the DDL so we can re-write this mess. Want to fix it or not?
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

Maybe you are looking for