ORA-01791: not a SELECTed expression - Order by

Hi,
Below query is executing in one system (database version 10.2 64 bit) without any error.
select distinct CONTRACTOR_ID,CONTRACTOR_NAME from CONTRACTOR order by REGISTRATION_NO
But same query is not working in other system (database version 10.2 32-bit). It throws ORA-01791: not a SELECTed expression error.
Please clarify why it is working in one system and not working in other system
Thanks,
Sujnan

Does the CONTRACTOR table have it's keys defined in both databases?
Oracle can decide to not do the DISTINCT (and thus allow such ORDER BY), in case it is aware of some key-column being selected. Take a look at this, same query, one works, one doesn't due to absence of primary key:
SQL> create table myemp(empno number not null primary key, job varchar2(10))
Table created.
SQL> select distinct empno from emp order by job;
     EMPNO
         2
         1
SQL> alter table emp drop primary key;
Table altered.
SQL> select distinct empno from emp order by job;
select distinct empno from emp order by job
ERROR at line 1:
ORA-01791: not a SELECTed expression
SQL>

Similar Messages

  • SQL Error: ORA-01791: not a SELECTed expression 01791. 00000 -  "not a SELE

    guys getting an error with a simple query. help me out please.
    the query is:
    select DISTINCT(product_code ||' ' || subproduct_code ||' '|| position_number) from alm_owner.wrr_recon_source order by product_code, subproduct_code, position_number;
    Error report:
    SQL Error: ORA-01791: not a SELECTed expression
    01791. 00000 - "not a SELECTed expression"
    *Cause:   
    *Action:
    any help is much appriciated.

    Raghunadh wrote:
    Yes. If he wants the result to be sorted on product_code, he can do something like:
    select DISTINCT Det from (
    select product_code ||' ' || subproduct_code ||' '|| position_number as Det
    from alm_owner.wrr_recon_source)
    order by substr(product_code,1);This will atleast sort the first section of the result. For example,
    @raghu> select distinct det from (select empno ||' ' || ename ||' '|| sal Det from emp);
    DET
    7499 ALLEN 1600
    7369 SMITH 5600
    7844 TURNER 7000
    7900 JAMES 950
    7654 MARTIN 6500
    7698 BLAKE 2850
    7788 SCOTT 3000
    7934 MILLER 6600
    7566 JONES 2975
    7839 KING 5000
    7521 WARD 1250
    7369 SMITH 800
    7844 TURNER 1500
    7876 ADAMS 1100
    7934 MILLER 1300
    7876 ADAMS 6200
    7782 CLARK 2450
    7521 WARD 6500
    7900 JAMES 5900
    7902 FORD 3000
    @raghu> select distinct det from (
    2  select empno ||' ' || ename ||' '|| sal Det from emp) order by substr(det,1);
    DET
    7369 SMITH 5600
    7369 SMITH 800
    7499 ALLEN 1600
    7521 WARD 1250
    7521 WARD 6500
    7566 JONES 2975
    7654 MARTIN 6500
    7698 BLAKE 2850
    7782 CLARK 2450
    7788 SCOTT 3000
    7839 KING 5000
    7844 TURNER 1500
    7844 TURNER 7000
    7876 ADAMS 1100
    7876 ADAMS 6200
    7900 JAMES 5900
    7900 JAMES 950
    7902 FORD 3000
    7934 MILLER 1300
    7934 MILLER 6600(Dont worry about the records in emp table, I inserted some sample duplicate records to test something)I don't understand what SUBSTR(det,1) is for. That's the same as ORDER BY det surely? Which is also the same as ORDER BY empno ||' ' || ename ||' '|| sal....
    Edited by: Bravid on Mar 2, 2012 11:56 AM

  • ORA-01791: not a SELECTed expression

    How can i fix this error? Any help is apprecaited..
    SQL> create table test(no number,no1 number);
    Table created.
    SQL> insert into test values(1,1);
    1 row created.
    SQL> select distinct no,no1
    2 from test order by no1;
    NO NO1
    1 1
    SQL> SELECT distinct no||'|'||no1 from test
    2 order by no1;
    order by no1
    ERROR at line 2:
    ORA-01791: not a SELECTed expression
    SQL>

    Shrinika wrote:
    How can i fix this error? Any help is apprecaited..
    SQL> create table test(no number,no1 number);
    Table created.
    SQL> insert into test values(1,1);
    1 row created.
    SQL> select distinct no,no1
    2 from test order by no1;
    NO NO1
    1 1
    SQL> SELECT distinct no||'|'||no1 from test
    2 order by no1;
    order by no1
    ERROR at line 2:
    ORA-01791: not a SELECTed expression
    SQL>SELECT distinct no||'|'||no1 from test order by 1;

  • Report Does Not Follow Select Column Order

    Hi all,
    Apex 2.2 on 10gXE
    I always encounter this problem, the display column on report does not follow the select column sequence order in the "region source".
    It is very tedious clicking the up/down arrow one-by-one in the "report attributes" especially if the display columns are plenty like 40 columns.
    Is there a fix/patch or alternative tips for this bug?
    Thanks a lot,
    Edited by: 843228 on May 24, 2011 10:32 PM

    Apex 2.2 on 10gXEStart by upgrading from this old unsupported version.
    >
    I always encounter this problem, the display column on report does not follow the select column sequence order in the "region source".
    It is very tedious clicking the up/down arrow one-by-one in the "report attributes" especially if the display columns are plenty like 40 columns.
    Is there a fix/patch or alternative tips for this bug?
    >
    This is not a bug. APEX maintains the original column order of the report. This avoids problems downstream in areas like the processing of <tt>g_fnn</tt> arrays in declarative tabular forms, where the assigned arrays are column-order dependent.
    APEX 4.x fixes column ordering bugs that could lead to report corruption, and includes drag-and-drop column ordering in the new tree view in addition to the up/down arrow re-ordering.
    If you really want column order to follow that in the source query, the workaround is to create a new report using the modified query.

  • ORA-00979 not a group expression

    below is my code. after i add select 2 new fields this error occurs.
    create or replace view v_sum_s_sectrx as
    select managergroupcode||securityid s_mgrgrp_secid, managergroupcode s_mgrgrp, securityid s_securityid,
    transactiontype s_trxtype, fromdate s_fromdate, todate s_todate,
    sum(units) s_units, sum(bookvalue) s_bookvalue, Fxcapitalgainlong, Fxcapitalgainshort
    from inv_xm_sectrx, mhfsta
    where transactiontype = 200
    and brokercode not in ('000',' ')
    and tanumber = tanum
    and poststatus != 68 -- deleted transaction
    group by 1, managergroupcode, securityid, transactiontype, fromdate, todate
    pls help.

    hehe i have solved it by add sum(field) to my two new fields.
    tks.

  • ORA-01791

    Hi All,
    I have this sql statement:
    Select Distinct EXTRACT(YEAR from A_DATE) from Attendances order by A_Date ASC;
    the error:
    ORA-01791: not a SELECTed expression

    SQL> with attendances as
      2  (select add_months(sysdate, level*12 ) a_date
      3   from   dual
      4   connect by level <= 10
      5  )
      6  --
      7  -- actual query:
      8  --
      9  select distinct extract(year from a_date) yr
    10  from   attendances
    11  order by extract(year from a_date) asc;
            YR
          2010
          2011
          2012
          2013
          2014
          2015
          2016
          2017
          2018
          2019
    10 rows selected.

  • 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:
    &#123;code&#125;
    (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.

  • ORA-00979: not a GROUP BY expression ORA-01722: invalid number error

    This is my follwing code:
    select isin,nomenclature,sum(total_balance),c_itd_rddt,c_itd_intrrt from
    select distinct instru.c_int_isin isin,
    instru.c_int_longdesc nomenclature,
    to_char(abs(acpos.acp_totbal),
    '999999999999,99,99,990.00')total_balance,
    c_itd_rddt,
    c_itd_intrrt
    from cs_instru_t instru,
    cs_instrudetls_t insdtls,
    cs_acpos_t acpos
    where instru.c_int_instruid = insdtls.c_itd_instruid
    and acpos.acp_instruid = instru.c_int_instruid
    and acpos.acp_acntnum = 'SG030001'
    and instru.c_int_instypid in (1)
    and insdtls.c_itd_rddt > ('31-Dec-2010')
    and instru.c_int_isin not in
    (select spsec.c_ssg_isinno from cs_splsecgrp_t spsec) and acpos.acp_totbal!=0
    group by instru.c_int_instruid,
    instru.c_int_longdesc,
    insdtls.c_itd_rddt,
    instru.c_int_insstts,
    instru.c_int_isin,
    insdtls.c_itd_rddt,
    acpos.acp_totbal,c_itd_intrrt
    --order by extract(year from  c_itd_rddt),c_itd_intrrt
    union
    select c_srm_prntisin isin,c_int_longdesc nomenclature,to_char(abs(acpos.acp_totbal),
    '999999999999,99,99,990.00') total_balance,c_itd_rddt,
    c_itd_intrrt from cs_instrudetls_t insdtls,cs_strmap_t map,cs_instru_strips instru,cs_acpos_t acpos
    where c_int_instruid=c_srm_prncplinsid
    and c_itd_instruid=c_int_instruid
    and c_srm_prncplinsid=acp_instruid
    and acp_acntnum='SG030001'
    )view1
    group by isin
    I want to group by isin only as only isin is same and the rest of the fields are different.But I want to display all the fields.Please Help
    I am getting the following errors:
    ORA-00979: not a GROUP BY expression
    ORA-01722: invalid number

    wat abt the other error ora-01722 not a valid number. How to take sum of total_balance which is to_char

  • "ORA-00979: not a GROUP BY expression" in Oracle11g R2 (11.2.0.3).

    Hi,
    We have a query which is working in 10g and giving error "ORA-00979: not a GROUP BY expression" in Oracle11g R2 (11.2.0.3). we have found following two solution to resolve it from the internet.
    1)You can Set the hidden parameter “_FIX_CONTROL”=’5520732:OFF’ in the pfile. This parameter disables a given bug number.
    2)We can set the parameter optimizer_features_enable to a previous version of Oracle, ’11.1.0.7′
    but I am unable to find the side effects of above change, so I need to know:
    1)whcih is batter solution
    2)what are the possible side effects of both solution.

    Hi Fran,
    Please find the below query.
    SELECT DECODE(TEMP.TENOR_IND, 'L', TEMP.SHORT_NAME, NULL) PRODUCT_NAME,
    TEMP.BA_PRODTYPE_ID,
    TEMP.TENOR,
    TEMP.PERIOD_TYPE,
    TEMP.PERIOD_VALUE,
    SUM(TEMP.LIMIT_BASE_AMOUNT),
    SUM(TEMP.PNDG_LIMIT_BASE_AMOUNT),
    SUM(TEMP.GROSS_EXP_BASE_AMOUNT),
    SUM(TEMP.NETT_EXP_BASE_AMOUNT),
    SUM(TEMP.COLLATERAL_BASE_AMOUNT),
    TEMP.TENOR_IND,
    MAX(TEMP.COB_DATE),
    TEMP.CRP_PRODUCT_GROUP
    FROM (SELECT /*+INDEX(LIM BUS_CB_LIMIT_INDX01) INDEX(btpd BUS_TP_PORTFOLIO_DTLS_INDX02)*/
    MCBPT.BA_PRODTYPE_ID,
    DECODE(LIM.TENOR_IND, 'L', MCBPT.SHORT_NAME, NULL),
    LIM.LIMIT_ID,
    LIM.LIMIT_TYPE_ID,
    LIM.LIMIT_STATUS,
    LIM.OWNER_ID,
    LIM.PERIOD_TYPE,
    LIM.PERIOD_VALUE,
    LIM.LIMIT_CURR,
    LIM.LIMIT_BASE_AMOUNT,
    LIM.GROSS_EXP_BASE_AMOUNT,
    DECODE(LIM.PERIOD_TYPE,
    5,
    'Inf',
    (TO_CHAR(LIM.PERIOD_VALUE) || '-' ||
    DECODE(LIM.PERIOD_TYPE, 4, 'Y', 3, 'M', 2, 'W', 1, 'D'))) TENOR,
    LIM.TENOR_SET_ID,
    LIM.PNDG_LIMIT_CURR,
    LIM.PNDG_LIMIT_BASE_AMOUNT,
    LIM.NETT_EXP_BASE_AMOUNT,
    LIM.COLLATERAL_BASE_AMOUNT,
    LIM.COB_DATE,
    LIM.TENOR_IND,
    MCBPT.CRP_PRODUCT_GROUP,
    MCBPT.SHORT_NAME
    FROM BUS_CB_LIMIT LIM,
    BUS_TP_PORTFOLIO_DETAILS BTPD,
    MST_CB_BA_PRODUCT_TYPE MCBPT
    WHERE BTPD.ORG_ID = 108503
    AND EXISTS
    (SELECT ORG_ID
    FROM BUS_CA_CORPORATE
    WHERE ORG_STAT IN (1, 2, 4, 7, 8, 9, 22, 24, 25)
    AND BTPD.BOOKING_ENTITY = ORG_ID
    START WITH ORG_ID = 894
    CONNECT BY PRIOR ORG_ID = PARENT_ORG_ID)
    AND NOT EXISTS
    (SELECT /*+INDEX(btpd1 BUS_TP_PORTFOLIO_DTLS_INDX02)*/
    btpd1.ba_prodtype_id
    FROM bus_tp_portfolio_details btpd1
    WHERE btpd1.org_id = 108503
    AND btpd1.booking_entity = 894
    AND BTPD.BA_PRODTYPE_ID = btpd1.ba_prodtype_id
    AND EXISTS
    (SELECT ba_prodtype_id
    FROM mst_cb_ba_product_type
    WHERE product_grp_id = 1
    AND btpd1.ba_prodtype_id = ba_prodtype_id))
    AND MCBPT.BA_PRODTYPE_ID = BTPD.BA_PRODTYPE_ID
    AND BTPD.CP_STATUS = 4
    AND LIM.OWNER_ID = BTPD.PORTFOLIO_ID
    AND LIM.OWNER_TYPE = 4
    AND LIM.LIMIT_TYPE_ID = 2) TEMP
    WHERE 1 = 1
    GROUP BY TEMP.BA_PRODTYPE_ID,
    TEMP.PERIOD_TYPE,
    TEMP.PERIOD_VALUE,
    TEMP.TENOR_IND,
    TEMP.SHORT_NAME,
    TEMP.CRP_PRODUCT_GROUP
    ORDER BY TEMP.BA_PRODTYPE_ID, TEMP.PERIOD_TYPE, TEMP.PERIOD_VALUE

  • 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

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

  • List View Report with pipelined function in Mobile application and ORA-01007: variable not in select list

    Hi!
    I have a problem with List View Report in mobile application (theme 50 in apex) after updating to apex 4.2.2. I created Report -> List View. I used select from pipelined function in Region Source. Then when page is running and submited three times (or refreshed three times) I get an error:
    Error during rendering of region "LIST VIEW".
    ORA-01007: variable not in select list
    Technical Info (only visible for developers)
    is_internal_error: true
    apex_error_code: APEX.REGION.UNHANDLED_ERROR
    ora_sqlcode: -1007
    ora_sqlerrm: ORA-01007: variable not in select list
    component.type: APEX_APPLICATION_PAGE_REGIONS
    component.id: 21230833903737364557
    component.name: LIST VIEW
    error_backtrace:
         ORA-06512: at "APEX_040200.WWV_FLOW_DISP_PAGE_PLUGS", line 4613
         ORA-06512: at "APEX_040200.WWV_FLOW_DISP_PAGE_PLUGS", line 3220
    I get this error only when I use select from pipelined function in Region Source (for example: "select value1, value2 from table(some_pipelined_function(param1, param2)) ").
    You can check it on http://apex.oracle.com/pls/apex/f?p=50591 (login - demo, password - demo).
    In this application:
    - I created package TAB_TYPES_PKG:
    create or replace PACKAGE TAB_TYPES_PKG IS
    TYPE cur_rest_r IS RECORD (
        STR_NAME          VARCHAR2(128),
        INFO              VARCHAR2(128)
    TYPE cur_rest_t IS TABLE OF cur_rest_r;
    END TAB_TYPES_PKG;
    - I created pipelined function TEST_FUNC:
    create or replace
    FUNCTION TEST_FUNC
    RETURN TAB_TYPES_PKG.cur_rest_t  PIPELINED IS
    r_cur_rest TAB_TYPES_PKG.cur_rest_r;
    BEGIN
    r_cur_rest.STR_NAME := 'ROW 1';
    r_cur_rest.INFO := '10';
    PIPE ROW (r_cur_rest);
    r_cur_rest.STR_NAME := 'ROW 2';
    r_cur_rest.INFO := '20';
    PIPE ROW (r_cur_rest);
    r_cur_rest.STR_NAME := 'ROW 3';
    r_cur_rest.INFO := '30';
    PIPE ROW (r_cur_rest);
    r_cur_rest.STR_NAME := 'ROW 4';
    r_cur_rest.INFO := '40';
    PIPE ROW (r_cur_rest);
    r_cur_rest.STR_NAME := 'ROW 5';
    r_cur_rest.INFO := '50';
    PIPE ROW (r_cur_rest);
    RETURN;
    END TEST_FUNC;
    - I created List View Report on Page 1:
    Region Source:
    SELECT str_name,
           info
    FROM TABLE (TEST_FUNC)
    We can see error ORA-01007 after refresing (or submiting) Page 1 three times or more.
    How to fix it?

    Hi all
    I'm experiencing the same issue.  Predictably on every third refresh I receive:
    Error
    Error during rendering of region "Results".
    ORA-01007: variable not in select list
    Technical Info (only visible for developers)
    is_internal_error: true
    apex_error_code: APEX.REGION.UNHANDLED_ERROR
    ora_sqlcode: -1007
    ora_sqlerrm: ORA-01007: variable not in select list
    component.type: APEX_APPLICATION_PAGE_REGIONS
    component.id: 6910805644140264
    component.name: Results
    error_backtrace: ORA-06512: at "APEX_040200.WWV_FLOW_DISP_PAGE_PLUGS", line 4613 ORA-06512: at "APEX_040200.WWV_FLOW_DISP_PAGE_PLUGS", line 3220
    OK
    I am running Application Express 4.2.2.00.11 on GlassFish 4 using Apex Listener 2.0.3.221.10.13.
    Please note: this works perfectly using a classic report in my desktop application; however, no joy on the mobile side with a list view.  I will use a classic report in the interim.
    My region source is as follows:
    SELECT description AS "DESCRIPTION", reference AS "REFERENCE" FROM TABLE(AUTOCOMPLETE_LIST_VIEW_FNC('RESULTS'))
    The procedure:
      FUNCTION AUTOCOMPLETE_LIST_VIEW_FNC(
          p_collection_name IN VARCHAR2)
        RETURN list_row_table_type
      AS
        v_tab list_row_table_type := list_row_table_type();
      BEGIN
        DECLARE
          jsonarray json_list;
          jsonobj json;
          json_clob CLOB;
        BEGIN
          SELECT clob001
          INTO json_clob
          FROM apex_collections
          WHERE collection_name = p_collection_name;
          jsonobj              := json(json_clob);
          jsonarray            := json_ext.get_json_list(jsonobj, 'predictions');
          FOR i IN 1..jsonArray.count
          LOOP
            jsonobj := json(jsonArray.get(i));
            v_tab.extend;
            v_tab(v_tab.LAST) := list_row_type(json_ext.get_string(jsonobj, 'description'), json_ext.get_string(jsonobj, 'reference'));
          END LOOP;
          RETURN(v_tab);
        END;  
      END AUTOCOMPLETE_LIST_VIEW_FNC;
    Thanks!
    Tim

  • Java.sql.SQLException: ORA-00979: not a GROUP BY expression in a query

    I am getting java.sql.SQLException: ORA-00979: not a GROUP BY expression
    when I run
    select count(*) from ( select count(rec_no) AS REC_NO_NUM,created_by AS
    CREATED_BY,to_char(created_dt,'Mon YYYY') AS CREATED_DT,to_date(to_char(created_dt,'Mon
    YYYY'),'Mon YYYY') AS CREATED_DATE from tbl_ndr_renal_reg where reg_no is not null and delete_ind
    = 'N' group by to_char(created_dt,'Mon YYYY'),created_by )
    But when I run the subquery below it doesn't give any error and returns rows.
    select count(rec_no) AS REC_NO_NUM,created_by AS CREATED_BY,to_char(created_dt,'Mon YYYY') AS
    CREATED_DT, to_date(to_char(created_dt,'Mon YYYY'),'Mon YYYY') AS CREATED_DATE from
    tbl_ndr_renal_reg where reg_no is not null and delete_ind = 'N' group by to_char(created_dt,'Mon
    YYYY'),created_by
    Thanks

    I tried that too still getting the same error
    SQL> select count(*) from (
    2 select count(rec_no) AS REC_NO_NUM,
    3 created_by AS CREATED_BY,
    4 to_char(created_dt,'Mon YYYY') AS CREATED_DT,
    5 to_date(to_char(created_dt,'Mon YYYY'),'Mon YYYY') AS CREATED_DATE
    6 from tbl_ndr_renal_reg
    7 where reg_no is not null
    8 and delete_ind = 'N'
    9 group by to_char(created_dt,'Mon YYYY'),created_by)
    10 ;
    to_date(to_char(created_dt,'Mon YYYY'),'Mon YYYY') AS CREATED_DATE
    ERROR at line 5:
    ORA-00979: not a GROUP BY expression

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

Maybe you are looking for

  • Problem in establishing connection with mysql 5.0

    Hi, I am using JCAPS 5.1. I tried to insert data to mysql database table. But i got following error java.sql.SQLException: Error in allocating a connection. Cause: Physical Connection doesn't exist. My intention is to read file in which data are comm

  • Server Admin not showing jobs in print queue

    Hi All, I'm not sure if others are having this problem or if it's just me.  I am running Mac Server OS X 10.6.7  When I go to Server Admin and select "Print" and then "Job Status", I get a list of all the server's print queues.  In the pane below the

  • Remove "Java Applet Window" from the window

    Hi, can anyone tell me how to remove the word "Java Applet Window" from a applet/frame/dialog running on the browser? Thank you very much. yunhe

  • Using vrfs with eigrp

    Hi Everyone I need to get two vrfs configured on some 3750 switches. I started off by configuring one vrf on three switches, A connected to B and B connected to C. The config was very simple like below but it didnt work: switch a example: ip vrf admi

  • Snow Leopard Clean Installation Issue

    I am having this problem right now. It will show the gray screen with the folder and the question mark. It is a 3 year old macbook pro that I was trying to do a clean install of snow leopard. i have the orignal pro installation disk, the leopard inst