GROUP BY: determinstic function column of group by expression 10g vs 11g

The following works in 10g but now fails in 11g.
Simple description: If I create a view of a number and subtract 2 from that number
and I group by the first column and include the 2nd column, it works in 10g and gives "not a group by column" in 11g.
It seems that 10g knew the 2nd column was derived by the first column so grouping by the 1st column gave an automatic pass to the 2nd column.
11g seems to be more strict (though I don't know why, if the 2nd column's function is purely deterministic as you would expect subtracting by 2 would be. Same is true for UPPER())
Is there a reason for this change in behaviour in 11g?
Is there some explicit reason for the change in functionality?
Exact versions and results below
Line: -----
Connected to:
Oracle Database 10g Release 10.2.0.3.0 - Production
SQL> drop view v1;
View dropped.
SQL> drop view v2;
View dropped.
SQL>
SQL> create view v1 as
2 select '0' c1, 0 c2 from dual
3 union all
4 select '1', 1 from dual
5 union all
6 select '2', 2 from dual
7 union all
8 select '3', 3 from dual;
View created.
SQL>
SQL>
SQL> create view v2
2 as select c1, upper(c1) c1u, c2, c2-2 c3
3 from v1;
View created.
SQL>
SQL> select c1, c1u
2 from v2
3 group by c1;
C C
1 1
3 3
0 0
2 2
SQL>
SQL> select c1, c2, c3
2 from v2
3 group by c1, c2;
C C2 C3
1 1 -1
3 3 1
2 2 0
0 0 -2
-- =============================================================================================
Connected to:
Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
SQL> drop view v1;
View dropped.
SQL> drop view v2;
View dropped.
SQL>
SQL> create view v1 as
2 select '0' c1, 0 c2 from dual
3 union all
4 select '1', 1 from dual
5 union all
6 select '2', 2 from dual
7 union all
8 select '3', 3 from dual;
View created.
SQL>
SQL>
SQL> create view v2
2 as select c1, upper(c1) c1u, c2, c2-2 c3
3 from v1;
View created.
SQL>
SQL> select c1, c1u
2 from v2
3 group by c1;
select c1, c1u
ERROR at line 1:
ORA-00979: not a GROUP BY expression
SQL>
SQL> select c1, c2, c3
2 from v2
3 group by c1, c2;
select c1, c2, c3
ERROR at line 1:
ORA-00979: not a GROUP BY expression
Edited by: joriotis on Jul 25, 2011 11:01 AM
Edited by: joriotis on Jul 25, 2011 11:03 AM

Hi,
Just 4 hours ago, someone else had a very similar question:
Group by fails on ORA-00979
Personally, I consider that a bug in Oracle 10. When you do a GROUP BY on a view, you can't expect the SQL engine to look at the view definition, and determine if one of the columns can be derived from another.
In practice, it's easy enough to add c1u to the GROUP BY clause, or to use MAX (c1u) instead of c1u, to make your query work.

Similar Messages

  • Ora-00979 not a group by expression

    hi , how r u ?
    my problem in group by , how include subquery in group by ,
    this query give me error ora-00979 not a group by expression ,
    please help me in this query :
    select EVV_CompScale.Code CompCode,ScaleCode ,NameEn,NameAr,RatingChar ,count(EV_CompetencyEmployee.Code) as VoteCount ,
    coalesce((select count(EV_CompetencyEmployee.code) from EV_CompetencyEmployee   join EV_EmployeeEvaluation tblEV on EV_Code=tblEV.Code  and EmployeeApprovalCMP=1 and DirectManagerApprovalCMP=1  and SeniorManagerApprovalCMP=1 and tblEV.configCode='K' where CompetencyCode=EVV_CompScale.Code  and not RatingID is null  ),1) as Total
    from EVV_CompScale left join (EV_CompetencyEmployee join EV_EmployeeEvaluation on EV_Code=EV_EmployeeEvaluation.Code and EmployeeApprovalCMP=1 and DirectManagerApprovalCMP=1 and SeniorManagerApprovalCMP=1 and EV_EmployeeEvaluation.configCode='K') on EV_CompetencyEmployee.CompetencyCode=EVV_CompScale.Code and RatingID=ScaleCode where CompConfig='K'
    and ScaleConfig='K' group by EVV_CompScale.Code,ScaleCode,RatingChar,NameEn,NameAr
    order by CompCode .
    thanks .

    Hi,
    In a GROUP BY querry, every item in the SELECT list must be one of the following
    (1) One of the GROUP BY expressions
    (2) An aggregate function
    (3) A constant
    (4) Deterministic expressions based on the above (for example, COALESCE, where all the arguments are taken from the list above)
    So if your scalar sub-query is going to be part of the GROUP BY query, it has to fit into one of those categories
    I don't see any good way of convincing the compiler that your scalar sub-query is a constant, even if it happens to rturn a constant value, but you can make it either
    (1) one of the GROUP BY expressions (compute it in a sub-query, to avoid repeating the whole scalar sub-query in the GROUP BY clause), or
    (2) an aggregate function ( e.g. MAX ((SELECT ...))).
    But the scalar sub-query doesn't have to be part of the GROUP BY query. Depending on your tables and the desired results, it might be easy to do the GROUP BY and what is now the scalar sub-query separately, and then join the two result sets.
    If you need help, it always 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) (You posted this, but since it's unformated, it's very hard to read.)
    (5) The full error message (if any), including line number
    Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
    Formatted tabular output is okay for (3). Type these 6 characters:
    {code}
    (small letters only, inside curly brackets) before and after formatted text, to preserve spacing.
    Simplify the problem if you can. For example, if your real query involves many columns and many join conditions, try to post a similar problem that has few columns and very siomple join conditions, but has the same problem as your real query.

  • Error : not a GROUP BY expression

    Hi everyone,
    Looks like i need some help here.. :) dont know what it means but im getting this message
    00979. 00000 - "not a GROUP BY expression"
    *Cause:   
    *Action:
    Error at Line: 137 Column: 36
    this is the function:
    function get_path(materialID in number, materialTypeID in number, inTopFolderID in number default null, inMaterialFolderID in number default null, webMode in number default 1)
    return varchar2;
    and im using it on my query
    ,(select material_util.get_path(m.material_id, 8, 1021695, min(mf.IP_MATERIALFOLDERID), 1)
    from material m, materialfolder mf
    where mf.nfx_link = m.MATERIAL_ID
    and m.template_id = t.template_id) as Path
    looks like min(mf.IP_MATERIALFOLDERID) is having some issues here.. dont know why..
    let me know guys..
    thanks..
    J

    A example
    with testdata as
    select 1 idu, 1 value1, 7 value2, 40 value3 from dual union all
    select 2 idu, 2 value1, 8 value2, 45 value3 from dual union all
    select 3 idu, 3 value1, 9 value2, 50 value3 from dual union all
    select 1 idu, 4 value1, 4 value2, 55 value3 from dual union all
    select 2 idu, 5 value1, 5 value2, 60 value3 from dual union all
    select 3 idu, 6 value1, 2 value2, 65 value3 from dual
    select min(value1), avg(value2), max(value1), sum(value3) from testdata;
    MIN(VALUE1) AVG(VALUE2) MAX(VALUE1) SUM(VALUE3)
    1 5,83333333333333333333333333333333333333 6 315
    Calculate the aggregated functions with all the data of the table.
    select idu, min(value1), avg(value2), max(value1), sum(value3) from testdata;
    Error SQL: ORA-00937:
    00937. 00000 - "not a single-group group function"
    Oracle don't know about what values have to calculate the aggrgates functions because there are not aggregated values in the select.
    select idu, min(value1), avg(value2), max(value1), sum(value3) from data group by idu;
    IDU MIN(VALUE1) AVG(VALUE2) MAX(VALUE1) SUM(VALUE3)
    1 1 5,5 4 95
    2 2 6,5 5 105
    3 3 5,5 6 115
    Calculate the aggregated functions in order at idu value.

  • Problems with GROUP BY - not a GROUP BY expression

    Hello,
    I am fighting little bit with GROUP BY expression.
    After some tests I am able to reduce the problem to following...
    When can I use column numbers in GROUP BY expression?
    Consider this situation:
    CREATE TABLE EMP4 (
       NAME VARCHAR2(10)
    COMMIT;
    INSERT INTO EMP4 VALUES('Tamara');
    INSERT INTO EMP4 VALUES('John');
    INSERT INTO EMP4 VALUES('Joseph');
    COMMIT;
    SELECT NAME, COUNT(*)
    FROM EMP4
    GROUP BY 1;
    00979. 00000 -  "not a GROUP BY expression"
    -- This is working
    SELECT NAME, COUNT(*)
    FROM EMP4
    GROUP BY NAME;Why is the GROUP BY 1 not workig?
    I am using the GROUP BY 1 because in real query there is some PL/SQL function which somehow modifies the column NAME, so I can't use the column name
    SELECT TEST_PACKAGE.AppendSomeCharacter(NAME), COUNT(*)
    FROM EMP4
    GROUP BY 1;Of course I can nest the query and move the COUNT and GROUP BY to outer query or maybe something else, but I was just curious why is the GROUP BY not working...
    Also in real query, there are 3 columns in the GROUP BY expression, so I have there GROUP BY 1, 2, 3
    Thanks for help

    hai
    try the following
    CREATE TABLE TBL(ID NUMBER,VAL VARCHAR(20));
    INSERT INTO TBL VALUES(1,'Z');
    INSERT INTO TBL VALUES(2,'X');
    INSERT INTO TBL VALUES(1,'Z');
    INSERT INTO TBL VALUES(2,'X');
    INSERT INTO TBL VALUES(3,'A');
    INSERT INTO TBL VALUES(4,'H');
    INSERT INTO TBL VALUES(5,'B');
    INSERT INTO TBL VALUES(6,'C');
    INSERT INTO TBL VALUES(7,'T');
    INSERT INTO TBL VALUES(3,'A');
    INSERT INTO TBL VALUES(4,'H');
    INSERT INTO TBL VALUES(5,'B');
    INSERT INTO TBL VALUES(6,'C');
    INSERT INTO TBL VALUES(7,'T');
    CREATE TYPE SAMPLETYPE AS OBJECT ( ID NUMBER, NAME
    VARCHAR2(25) ) ;
    CREATE TYPE SAMPETBLTYPE AS TABLE OF SAMPLETYPE;
    CREATE OR REPLACE FUNCTION SAMPLEFUNC
    p_colname varchar2
    )return SAMPETBLTYPE pipelined as
    ret_val SAMPLETYPE;
    TYPE cursor_ref IS REF CURSOR;
    fcur cursor_ref;
    di TBL%ROWTYPE;
    sqlstr varchar2(1000);
    colname varchar(30):=p_colname;
    begin
    sqlstr:='SELECT * FROM TBL ORDER BY '|| colname ;
    DBMS_OUTPUT.PUT_LINE(sqlstr);
    open fcur FOR sqlstr;
    loop
    FETCH fcur INTO di;
    EXIT WHEN fcur%NOTFOUND;
    ret_val:=SAMPLETYPE(di.ID,di.VAL);
    PIPE ROW(ret_val);
    end loop;
    close fcur;
    return;
    end;     
    select * from table(SAMPLEFUNC('ID'));
    select * from table(SAMPLEFUNC('VAL'));

  • Group by expression not found

    Hello,
    I have a query which is giving not a group by expression error even though after having all columns in group by clause,
    The crazy here is the same query is working fine in three environments expect in one environment.
    I did a work around on this if i use the sub query my issue is getting solved but performance is going down.
    I have a union all ,collection(Multiset) clause as well. :)
    Please let me know if you people have any idea/solution on this issue?
    Is this related any environmental setup on oracle.?
    Am using oracle 10g data base and oracle 11g for my .NET.
    Thanks,
    SanS

    From my experience I have got "not a group by" expression prob.
    for a select satement like this:::
    select tab1.id,tab1.name,count(tab2.col1)
    From tab1,tab2 where tab1.id=tab2.idx
    group by tab1.id,tab1.name
    order by lower(name);
    The prob.with order by lower(name) ....without 'lower' (any other functions) working fine...and the prob occurs when the record set called from the front end(asp.net)...directly executing from the db its working fine...
    regards,
    jp@valapad

  • Please help : not a group by expressions

    not a group by expressions,
    SELECT a.BATCH_ID, a.ASSOCIATE_NAME,count(a.ID)
    FROM ASSOCIATE1 a,SEMESTER1 s, BATCH1 b
    WHERE s.ID=b.SEMESTER_ID
    AND b.ID=a.BATCH_ID
    AND to_char(s.END_DATE,'DD-MON-YY')>'25-APR-13'
    AND to_char(s.END_DATE,'DD-MON-YY')<'25-MAY-13'
    GROUP BY a.BATCH_ID
    please help :( I get this error a lot of time, I dont know what I lack about the knowledge of group by function

    Hi,
    1001317 wrote:
    not a group by expressions,
    SELECT a.BATCH_ID, a.ASSOCIATE_NAME,count(a.ID)
    FROM ASSOCIATE1 a,SEMESTER1 s, BATCH1 b
    WHERE s.ID=b.SEMESTER_ID
    AND b.ID=a.BATCH_ID
    AND to_char(s.END_DATE,'DD-MON-YY')>'25-APR-13'
    AND to_char(s.END_DATE,'DD-MON-YY')<'25-MAY-13'
    GROUP BY a.BATCH_ID
    please help :( I get this error a lot of time, I dont know what I lack about the knowledge of group by functionHere are the ABC's of GROUP BY:
    When you use a GROUP BY clause and/or an aggregate function, then everything in the SELECT clause must be:
    (A) an <b>A</b>ggregate function,
    (B) one of the "group <b>B</b>y" expressions,
    (C) a <b>C</b>onstant, or
    (D) something that <b>D</b>epends entirely on the above. (For example, if you "GROUP BY TRUNC(dt)", you can SELECT "TO_CHAR (TRUNC(dt), 'Mon-DD')").
    In your case, the SELECT clause includes:
    COUNT (a.id)     which is an aggregate (A), so it's okay,
    a.batch_id     which is in the GROUP BY clause (B), so it's okay, and
    a.associate_name     which is none of the above.
    "GROUP BY a.batch_id" means the otput will contain 1 row for every distinct value of a.batch_id. What if there are several rows with the same value of a.batch_id: which of the several values of a.associate_name would you want to include? If your data is such that there can only be 1 distinct value of a.associate_name for each distinct value of a.batch_id, then it doesn't matter which of them is included (they are all the same), so you can use MIN (a.associate_name) or MAX (a.associate_name), or, even better, include a.associate_name in the GROUP BY clause.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}
    &nbps
    By the way:
    AND to_char(s.END_DATE,'DD-MON-YY')>'25-APR-13'
    AND to_char(s.END_DATE,'DD-MON-YY')<'25-MAY-13'I don't think you really mean what you said on the 2 lines above. You porbably meant
    {code
    AND s.END_DATE > TO_DATE ('25-APR-2013', 'DD-Mon-YYYY')
    AND s.END_DATE < TO_DATE ('25-MAY-2013', 'DD-Mon-YYYY')

  • Error using group by expression

    hello friends,
    I use this query & used group by but oracle give error :
    ORA-00979: not a GROUP BY expression
    Select uu.ID,max(uu.module_name) as MainMenu,uu.NAME,decode(substr(param_str,4,1), 'P','ü','') as Allow,decode(substr(param_str,1,1), 'A','ü','') as Ins,decode(substr(param_str,2,1), 'E','ü','') as Edit,decode(substr(param_str,3,1), 'D','ü','') as Del from USER_MODULE uu,user1 where( user_name='SA'or user_name is null)and user1.srno=uu.srno and uu.ID=uu.ID group by uu.id,uu.name,MainMenu group by uu.id,uu.name

    Hi
    The 'param_str' in DECODE function either should be a bind variable for user input or should be a column of a table. If it is a table/view column then include it in the GROUP BY clause and the query should work.
    If you specify a GROUP BY clause in a statement, then the select list can
    contain only the following types of expressions:
    – GROUP BY expressions
    – Constants
    – Aggregate functions and the functions USER, UID, and SYSDATE
    – Expressions identical to those in the group_by_clause. If the group_by_
    clause is in a subquery, then the GROUP BY columns of the subquery must
    match the select list of the outer query. Any columns in the select list of the
    subquery that are not needed by the GROUP BY operation are ignored without
    error.
    – Expressions involving the preceding expressions that evaluate to the same
    value for all rows in a group
    In short, except for the columns in aggregate functions, all columns must be included in the GROUP BY clause.
    - Priya

  • Getting "ORA-00979: not a GROUP BY expression" error in Inline query

    Hello all,
    The following query when run in SCOTT user gives "ORA-00979: not a GROUP BY expression" error.
    If I remove the TRUNC function from the outer query's group by clause, then it fetches
    (My actual query is something similar to the following query. I have given emp, dept tables for convenience's sake)
    select e.empno,e.ename, AVG(e.SAL), trunc(e.hiredate),
    (select sum(sal) from emp
    where hiredate = e.hiredate) salary
    from emp e
    group by e.DEPTNO,e.EMPNO,e.ENAME, trunc(e.hiredate)
    Pls suggest how this error can be avoided.
    Regards,
    Sam

    Why not this?
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Elapsed: 00:00:00.02
    satyaki>
    satyaki>
    satyaki>select e.empno,
      2         e.ename,
      3         AVG(e.SAL),
      4         trunc(e.hiredate),
      5        (
      6           select sum(sal)
      7           from emp
      8           where hiredate = e.hiredate
      9        ) salary
    10  from emp e
    11  group by e.DEPTNO,
    12           e.EMPNO,
    13           e.ENAME,
    14           e.hiredate;
         EMPNO ENAME      AVG(E.SAL) TRUNC(E.H     SALARY
          7934 MILLER         1887.6 23-JAN-82     5583.6
          7698 Glen             1848 23-JAN-82     5583.6
          7788 SCOTT          598.95 19-APR-87     598.95
          7900 JAMES          1379.4 03-DEC-81    6650.16
          7521 WARD           226.88 22-FEB-81     226.88
          7599 BILLY            4500 10-JUN-09       4500
          2222 sp               1200 14-SEP-09       1200
          7902 FORD          5270.76 03-DEC-81    6650.16
          7566 Smith            1848 23-JAN-82     5583.6
          7654 MARTIN           1815 28-SEP-81       1815
          7839 KING             7260 17-NOV-81       7260
         EMPNO ENAME      AVG(E.SAL) TRUNC(E.H     SALARY
          7844 TURNER           2178 08-SEP-81       2178
          7876 ADAMS          159.72 23-MAY-87     159.72
    13 rows selected.
    Elapsed: 00:00:00.03
    satyaki>Regards.
    Satyaki De.

  • NOT A GROUP BY EXPRESSION

    Good Evening,
    Maybe someone out there can help me out. I have been working on this rather long statement. Line 5 which has the to_char function is throwing an error and I don't know how to get around it. Without this line the query returns the desired results.
    Any suggestions would be appreciated.
    thanks for your help in advance.
    al
    The error message reads:
    to_char(logon_time, 'DD-MON-YY HH:MI:SS PM') LOGON_TIME,
    ERROR at line 5:
    ORA-00979: not a GROUP BY expression
    The statement is one I found in one of my manuals. I did not create this myself!
    select * from
    (select b.sid, decode(b.username, null, e.name, b.username) USER_NAME,
         d.spid OS_ID,
         b.machine MACHINE_NAME,
         --to_char(logon_time, ‘DD-MON-YY  HH:MI:SS PM’)  LOGON_TIME,
         (sum(decode(c.name, ‘physical reads’, c.statistic#, 0)) +
              sum(decode(c.name, ‘physical writes’, c.statistic#, 0)) +
              sum(decode(c.name, ‘physical writes direct’, c.statistic#, 0)) +
              sum(decode(c.name, ‘physical writes direct (lob)’, c.statistic#, 0)) +
              sum(decode(c.name, ‘physical reads direct (lob)’, c.statistic#, 0)) +
         sum(decode(c.name, ‘physical reads direct’, c.statistic#, 0))) total_physical_io,
         (sum(decode(c.NAME, ‘db block gets’, c.statistic#, 0)) +
    sum(decode(c.NAME, ‘db block changes’, c.statistic#, 0)) +
    sum(decode(c.NAME, ‘consistent changes’, c.statistic#, 0)) +
    sum(decode(c.NAME ,‘consistent gets’, c.statistic# ,0)) ) total_logical_io,
         (sum(decode(c.NAME, ‘session pga memory’, c.statistic#, 0)) +
    sum(decode(c.NAME, ‘session uga memory’, c.statistic# , 0)) ) total_memory_usage,
    sum(decode(c.NAME, ‘parse count (total)‘, c.statistic#, 0)) parses,
    sum(decode(c.NAME, ‘CPU used by this session‘,c.statistic#, 0)) total_cpu,
    sum(decode(c.NAME, ‘parse time cpu‘,c.statistic# , 0)) parse_cpu,
    sum(decode(c.NAME, ‘recursive cpu usage‘,c.statistic#, 0)) recursive_cpu ,
              sum(decode(c.NAME, ‘CPU used by this session‘, c.statistic# , 0)) –
    sum(decode(c.NAME, ‘parse time cpu‘, c.statistic#, 0)) –
    sum(decode(c.NAME, ‘recursive cpu usage‘, c.statistic# , 0)) other_cpu,
    sum(decode(c.NAME, ‘sorts (disk)‘, c.statistic#, 0)) disk_sorts,
    sum(decode(c.NAME, ‘sorts (memory)‘, c.statistic#, 0)) memory_sorts,
    sum(decode(c.NAME, ‘sorts (rows)‘, c.statistic#, 0)) rows_sorted,
    sum(decode(c.NAME, ‘user commits‘, c.statistic# , 0)) commits,
    sum(decode(c.NAME, ‘user rollbacks‘,c.statistic# , 0)) rollbacks,
    sum(decode(c.NAME, ‘execute count‘, c.statistic#, 0)) executions
    from v_$session b, v_$process d, v_$bgprocess e, v_$statname c, v_$sesstat a
    where a.STATISTIC# = c.STATISTIC# and
    b.SID = a.SID AND
    d.addr = b.paddr and
    e.paddr (+) = b.paddr and
    c.NAME in (‘physical reads’,
              ‘physical writes’,
              ‘physical writes direct’,
              ‘physical reads direct’,
              ‘physical writes direct (lob)’,
              ‘physical reads direct (log)’,
              ‘db block gets’,
              ‘db block changes’,
              ‘consistent changes’,
              ‘consistent gets’,
              ‘session pga memory’,
              ‘sessionuga memory’,
              ‘parse count (total)’,
              ‘CPU used by this session’,
              ‘parse time cpu’,
              ‘recursive cpu usage’,
              ‘sorts (disk)’,
              ‘sorts (memory)’,
              ‘sorts (rows)’,
              ‘user commits’,
              ‘user rollbacks’,
              ‘execute count’
    GROUP BY b.SID,
              D.SPID,
              DECODE (b.USERNAME, NULL, e.name, b.username), b.machine,
              to_char(logon_time, ‘DD-MON-YY HH:MI:SS PM’)
    ORDER BY 6 DESC)
    WHERE rownum <21;

    Try changing your GROUP BY from:
    GROUP BY b.SID,D.SPID,DECODE (b.USERNAME, NULL, e.name, b.username), b.machine,to_char(logon_time, ‘DD-MON-YY HH:MI:SS PM’)to:
    GROUP BY b.SID,D.SPID,DECODE (b.USERNAME, NULL, e.name, b.username), b.machine,logon_time

  • ORA-00979: not a GROUP BY expression on different oracle version

    Hi,
    I tried below sql on different database and I'm having a strange result.
    error is ORA-00979: not a GROUP BY expression
    SELECT COUNT(*) OVER() CNT,
    COUNT(member_id) AS cnt2,
    etoc_type,
    journal_id,
    volume_id,
    issue_id,
    current_registered_users,
    date_sent,
    date_order,
    (COUNT(member_id) -
    (Select Count( *)
    FROM oracjoc.email_alert_bounce_backs bb
    WHERE aa.journal_id = bb.journal_id
    AND aa.volume_id = bb.volume_id
    AND aa.issue_id = bb.issue_id
    AND aa.etoc_type = bb.etoc_type
    AND aa.date_sent = TO_CHAR(bb.date_sent, 'ddMonYYYY')
    )) delivered
    FROM
    (SELECT member_id,
    etoc_type,
    journal_id,
    volume_id,
    issue_id,
    current_registered_users,
    TO_CHAR(date_sent, 'ddMonyyyy') date_sent,
    To_Number(To_Char(Date_Sent, 'yyyymmdd')) Date_Order
    FROM oracjoc.Report_Issue_Alert
    WHERE Etoc_Type = '1'
    ) Aa
    GROUP BY Journal_Id,
    Volume_Id,
    Issue_Id,
    Etoc_Type,
    Current_Registered_Users,
    Date_Order,
    Date_Sent
    ORDER BY date_order DESC
    Oracle version:
    Oracle Database 11g Release 11.1.0.7.0 - 64bit Production: I got failed result on this one
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production: sql was successfully executed.
    Can someone explain is this still a part of bug on non enterprise edition?, TIA!

    919272 wrote:
    Hi,
    I tried below sql on different database and I'm having a strange result.
    error is ORA-00979: not a GROUP BY expressionRead the full error message. It has also a row and a column number specified. Use this number to find out which column gives you the trouble.
    I see that there are several not needed date to char conversions. I could imaging that they confuse the query merge mechanism. Other than that: try to strip down the query to the smallest posisble set of colum combination. So that you can see where the error comes from.
    SELECT COUNT(*) OVER() CNT,
    COUNT(*) AS cnt2,
    etoc_type,
    journal_id,
    volume_id,
    issue_id,
    current_registered_users,
    date_sent2,
    (COUNT(*) -
      (Select Count( *)
        FROM oracjoc.email_alert_bounce_backs bb
        WHERE aa.journal_id = bb.journal_id
        AND aa.volume_id = bb.volume_id
        AND aa.issue_id = bb.issue_id
        AND aa.etoc_type = bb.etoc_type
        AND aa.date_sent2 = trunc(bb.date_sent)
        )) delivered
    FROM  (SELECT member_id, etoc_type, journal_id, volume_id, issue_id, current_registered_users,
           trunc(date_sent) date_sent2,
    FROM oracjoc.Report_Issue_Alert
    WHERE Etoc_Type = '1'
    ) Aa
    GROUP BY Journal_Id, Volume_Id, Issue_Id, Etoc_Type, Current_Registered_Users, Date_Sent2
    ORDER BY Date_Sent2 DESC

  • ORA-00979: not a GROUP BY expression in Oracle11g R2

    hi,
    I am working in Oracle 9i Environement. I want to update Our production database from Oracle 9i to Oracle11g R2.
    Note :- Oracle 9i & 11g R2 are different systems.
    We follow the migration through import & Export Commands from Production database to New Database.
    One Of user having views, while executing that view in 11g R2 Environment it gives the following error.
    ORA-00979: not a GROUP BY expression.
    When i run this same Query in Oracle9i Environment is executed Successfully with out errors or warnings.
    This type of problem not occurred in all views.
    In Problematic view having Decode function with in that another decode method was used & finally group by clause is used.
    Please guide to me if any issues in 11g R2 Environment.
    Thanx in advance
    Vijay Kumar
    Edited by: user1672302 on Apr 4, 2012 5:32 PM

    Pl see these MOS Docs
    ORA-00979 AFTER UPGRADE TO 11G [ID 814423.1]     
    SQL used to work in 10G Throws ORA-00979 Not A Group By Expression after upgrading to 11G [ID 813946.1]     
    HTH
    Srini

  • GROUP BY with parameter - cause error -ORA-00979: not a GROUP BY expression

    I generate a query via PreparedStatement. For example:
    SELECT when, value FROM test GROUP BY ?;
    PrepState.toString(1, "when");
    That causing error: ORA-00979: not a GROUP BY expression
    My application using query like:
    SELECT to_char(data,1), SUM(vlue) as sum FROM test GROUP BY to_char(data, 2);
    PrepState.toString(1, "YYYY-MM");
    PrepState.toString(2, "YYYY-MM");

    Ah. Reproduced in the first chunk of PL/SQL below.
    The second chunk is a workaround.
    Basically, SQL is parsed by the syntax engine and optimizer to get an execution plan. Then you can have a sequence of "bind, execute, fetch, fetch, fetch..., bind, execute..."
    Since you can have multiple binds for a single SQL parse, then the fact that the first set of binds all happen to have the same value doesn't mean the next set will.
    The optimizer needs to be 100% sure that the value in the select must always be the same as the value in the group by, so you can't have two separate (and therefore potentially different) bind variable mappings. [Given the right circumstances, the optimizer might do all sorts of tricks, such as using materialized views and function-based indexes.]
    Misleadingly, it actually fails on the 'EXECUTE' step of DBMS_SQL rather than the PARSE.
    declare
      v_sql varchar2(1000) :=
        'select to_char(created,:b1), count(*) '||
        ' from user_objects u '||
        ' group by to_char(created,:b2) '||
        ' order by to_char(created,:b3)';
      v_fmt varchar2(10) := 'YYYY';
      v_cur number;
      v_ret_str varchar2(10);
      v_ret_num number;
      v_ret number;
    begin
      v_cur := dbms_sql.open_cursor;
      dbms_sql.parse(v_cur, v_sql, dbms_sql.native );
      dbms_sql.define_column_char (v_cur, 1, v_ret_str, 10);
      dbms_sql.define_column (v_cur, 2, v_ret_num);
      dbms_sql.bind_variable( v_cur, ':b1', v_fmt );
      dbms_sql.bind_variable( v_cur, ':b2', v_fmt );
      dbms_sql.bind_variable( v_cur, ':b3', v_fmt );
      v_ret := dbms_sql.execute( v_cur );
      WHILE ( dbms_sql.fetch_rows(v_cur) > 0 ) LOOP
        dbms_sql.column_value_char (v_cur, 1, v_ret_str );
        dbms_sql.column_value (v_cur, 2, v_ret_num );
        dbms_output.put_line('>'||v_ret_str||':'||v_ret_num);
      END LOOP;
    end;
    declare
      v_sql varchar2(1000) :=
        'select to_char(created,f.fmt), count(*) '||
        ' from user_objects u, (select :b1 fmt from dual) f '||
        ' group by to_char(created,f.fmt) '||
        ' order by to_char(created,f.fmt)';
      v_fmt varchar2(10) := 'YYYY';
      v_cur number;
      v_ret_str varchar2(10);
      v_ret_num number;
      v_ret number;
    begin
      v_cur := dbms_sql.open_cursor;
      dbms_sql.parse(v_cur, v_sql, dbms_sql.native );
      dbms_sql.define_column_char (v_cur, 1, v_ret_str, 10);
      dbms_sql.define_column (v_cur, 2, v_ret_num);
      dbms_sql.bind_variable( v_cur, ':b1', v_fmt );
      v_ret := dbms_sql.execute( v_cur );
      WHILE ( dbms_sql.fetch_rows(v_cur) > 0 ) LOOP
        dbms_sql.column_value_char (v_cur, 1, v_ret_str );
        dbms_sql.column_value (v_cur, 2, v_ret_num );
        dbms_output.put_line('>'||v_ret_str||':'||v_ret_num);
      END LOOP;
    end;
    /

  • Error ORA-00979: not a GROUP BY expression

    I have to run a query to list the Product_code, stock_level, and the total quantity ordered
    The tables are as follows:
    PRODUCT:
    PRODUCTCODE     PRODDESCRIPTION     PRICE     STOCKLEVEL
    p1      carpet     40     10000
    p2      tile     20     100000
    p3      pergo     50     50000
    PRODLINE:
    ORDERNUMBER     PRODCODE     QUANTITY
    o1      p1      1000
    o1      p2      500
    o2      p3      200
    o3      p1      600
    o3      p3      100
    o4      p2      1000
    o5      p2      800
    Here is my SQL Statement:
    SELECT pl.PRODCODE, SUM(pl.QUANTITY), pr.STOCKLEVEL
    FROM PRODLINE pl, PRODUCT pr
    WHERE pl.PRODCODE=pr.PRODUCTCODE
    GROUP BY pl.PRODCODE;
    RESULT:
    ORA-00979: not a GROUP BY expression
    Can someone please assist?

    Welconme to the forum!
    895231 wrote:
    ... Here is my SQL Statement:
    SELECT pl.PRODCODE, SUM(pl.QUANTITY), pr.STOCKLEVEL
    FROM PRODLINE pl, PRODUCT pr
    WHERE pl.PRODCODE=pr.PRODUCTCODE
    GROUP BY pl.PRODCODE;
    RESULT:
    ORA-00979: not a GROUP BY expression
    Can someone please assist?Remember the ABC's of GROUP BY:
    When you use a GROUP BY clause and/or an aggregate fucntion, then everything in the SELECT clause must be:
    (A) an <b>A</b>ggregate function,
    (B) one of the "group <b>B</b>y" expressions,
    (C) a <b>C</b>onstant, or
    (D) something that <b>D</b>epends entirely on the above. (For example, if you "GROUP BY TRUNC(dt)", you can SELECT "TO_CHAR (TRUNC(dt), 'Mon-DD')").
    In your query, pr.stocklevel is none of the above.
    The previous respondent show how you can make it one of the "group <b>B</b>y" expressions, which is noramlly how you would handle this situation.
    Alternatively, you could make it an <b>A</b>ggregate function, like this:
    SELECT       pl.PRODCODE
    ,       SUM (pl.QUANTITY)     AS total_quantity
    ,       MIN (pr.STOCKLEVEL)     AS stokclevel
    FROM        PRODLINE      pl
    ,        PRODUCT      pr
    WHERE       pl.PRODCODE     = pr.PRODUCTCODE
    GROUP BY  pl.PRODCODE;

  • ORA-000979: not a GROUP BY expression

    I am passing parameters to TOTAL_AMOUNT function in a package.the function waht it will do is it will
    round off the amount.when i execute this query i am egtting below exception .
    ORA-000979: not a GROUP BY expression
    SELECT
         UTILITIES_PKG.TOTAL_AMOUNT ((SELECT SUM(EII1.QTY) * EII1.PRICE
    FROM
    EMPLOYEE_ITEMS EII1
    WHERE
    EII1.EMP_ID=E.ID
    GROUP BY
                             EII1.ID,
    EII1.PRICE
    E.EMP_ID,
    E.EMPCUR_ID
    ) AMOUNT
                        FROM EMPLOYEE E,
                        EMPLOYEE_ITEMS EII
                        WHERE
                        EII1.EMP_ID=E.ID

    have you tried passing the actual parameter value to verify if the package function is the issue?
    e.g.
        select utilities_pkg.total_amount(100,20,5) from dual
    or should it be
         SELECT SUM(EII1.QTY * EII1.PRICE) tot_amt
           FROM EMPLOYEE_ITEMS EII1,
                EMPLOYEE       E
          WHERE EII1.EMP_ID = E.ID
         GROUP BY EII1.ID, EII1.PRICE

  • Performance... Why a function column in a view is executed more than once...?

    Why a function column created inside a view is executed more than once when called more than once?
    EXAMPLE:
    create or replace view aux1 as
    date_column,
    any_function(date_column) column1
    from any_table
    create or replace view aux2 as
    column1 c1,
    column1 c2,
    column1 c3
    from aux1
    select * from aux2
    It will execute 3 times the function any_function... logically the value will be the same for all columns...
    I understand why!... are 3 calls... but...
    Why not to create a "small" verification and if the function column was execute replace the second, the third... value? ... instead of execute 3, 4... times...
    tks
    Braga

    Actually, this is more than a performance issue. This is a consistency problem. If the function is NOT deterministic then you may get different values for each call which is clearly not consistent with selecting 3 copies of the same column from a row. Oracle appears to have fixed this in 9i...
    Connected to:
    Oracle8i Enterprise Edition Release 8.1.7.2.0 - Production
    With the Partitioning option
    JServer Release 8.1.7.2.0 - Production
    create view v1 as select dbms_random.value(1,100) r from dual;
    create view v2 as select r r1, r r2 from v1;
    select * from v2;
              R1           R2
              93           74
    Connected to:
    Oracle9i Enterprise Edition Release 9.0.1.3.0 - Production
    With the Partitioning option
    JServer Release 9.0.1.3.0 - Production
    create view v1 as select dbms_random.value(1,100) r from dual;
    create view v2 as select r r1, r r2 from v1;
    select * from v2;
              R1           R2
              78           78Richard

Maybe you are looking for