SQL & PL/SQL :: ORA-00979 - Not A GROUP BY Expression At Runtime?
Oct 13, 2010
I ran into something that has me wondering about which errors are caught at compile-time, and which are caught at runtime. There is a pretty big package with lots of complicated queries that heavily use GROUP BY, and in the last couple of years I thought I never had the case of an ORA-00979 happening an RUNTIME, which is now happening.
The last heavy changes in that package did I make in the Oracle 9.2 days, and I *believe* (although my memory might be wrong) that back then the ORA-00979 errors came up at compile time.
So is it normal that the error doesn't show up during compile time, only during runtime, or should it be considered a bug?
SQL> CREATE TABLE test_tab(a NUMBER(1), b NUMBER(1));
Table created.
SQL> INSERT INTO test_tab VALUES (1,1);
1 row created.
SQL>
SQL> CREATE OR REPLACE PROCEDURE test_prod AS
2 v_a NUMBER;
3 v_b NUMBER;
4 BEGIN
5
6 SELECT a,b
7 INTO v_a, v_b
8 FROM test_tab
9 GROUP BY a;
10
11 END;
12 /
Procedure created.
SQL>
SQL> BEGIN
2 test_prod;
3 END;
4 /
BEGIN
*
ERROR at line 1:
ORA-00979: not a GROUP BY expression
ORA-06512: at "PFK.TEST_PROD", line 6
ORA-06512: at line 2
I wrote a query for minimum average salary of Job_id using inline view but it is not working..
The query is as follow
SELECT job_id, avg(salary) FROM employees , (SELECT MIN(AVG(salary)) min_avg_sal FROM employees GROUP BY job_id) b GROUP BY job_id having avg(salary)=b.min_avg_sal;
It returns error as
################################ having avg(salary)=b.min_avg_sal * ERROR at line 6: ORA-00979: not a GROUP BY expression #########################
I read that rownum is applied after the selection is made and before "order by". So, in order to get the sum of salaries for all employees in all departments with a row number starting from 1, i wrote :
select ROWNUM,department_id,sum(salary) from employees group by department_id
If i remove rownum, it gives the correct output. Why can't rownum be used here ?
when i am running the below plsql block i am getting the error like not a group by expressiong.
DECLARE CURSOR Cur_st IS SELECT DISTINCT CAST (A.STO_NO AS VARCHAR2 (5 CHAR)) AS BU_CODE, CAST ('STO' AS VARCHAR2 (3 CHAR)) AS BU_TYPE, CAST (NULL AS VARCHAR2 (7 BYTE)) AS CUST_NO, CAST (A.CUR_CODE AS VARCHAR2 (3 BYTE)) AS CUR_CODE, TO_DATE (A.SALES_DATE, 'YYMMDD'), CAST (A.RECEIPT_NO AS VARCHAR2 (10 BYTE)), [code]....
Say for example, I want to group by the fields "Type" and and expression called "expression" (which is a case statement). I tried running this query and it says "expression" is invalide identifier.
select type, case when SUBSTR (glnumber, 1, 2) = '05' then 'IS' when SUBSTR (glnumber, 1, 2) = '06' then 'IS' else 'BS' end "expression" , sum(balance) from table group by TYPE, "expression"
If there is any online material on how to GROUP BY on an expression(like above)
way to set the properties of a visual attribute group during runtime? During our forms 6 to 10 conversion we missed that our visual attributes for mandatory and not-manadatory items were different, so we have font size 8 and 9 in our system now, does not look very nice.
I'm trying to group sets of data based on time separations between records and then count how many records are in each group.
In the example below, I want to return the count for each group of data, so Group 1=5, Group 2=5 and Group 3=5
SELECT AREA_ID AS "AREA ID", LOC_ID AS "LOCATION ID", TEST_DATE AS "DATE", TEST_TIME AS "TIME" FROM MON_TEST_MASTER WHERE AREA_ID =89 AND LOC_ID ='3015' AND TEST_DATE ='10/19/1994';
[code]....
Group 1 = 8:00:22 to 8:41:22
Group 2 = 11:35:47 to 11:35:47
Group 3 = 15:13:46 to 15:13:46
Keep in mind the times will always change, and sometime go over the one hour mark, but no group will have more then a one hour separation between records.
I'm working with Object types containing other object types, and I'm getting the error PLS-00363 (Expression cannot be used as an assignment).I'm putting exlpicity all 'SELF' parameters as 'IN OUT', but still get the error...
CREATE OR REPLACE TYPE TYP_PERSON AS OBJECT ( strName VARCHAR2(100), -- CONSTRUCTOR FUNCTION TYP_PERSON RETURN SELF AS RESULT, -- MEMBER FUNCTION getName (SELF IN OUT TYP_PERSON) RETURN VARCHAR2, MEMBER PROCEDURE setName (SELF IN OUT TYP_PERSON, pNewName VARCHAR2) ) NOT FINAL; [code]....
How can I do this parentObject.getChildObject().setChildFunction()?
im trying to take a query that pulls all the info in the current tables, and narrow it down to one day plus current. here is the error i am getting.
(SELECT OH.ORD_CNTRL_NO, OH.ORD_NO, OH.ASSGN_SHIP_DATE, oh.account_no, sum(OL.ORD_QTY) AS ORD_QTY * ERROR at line 5: ORA-00936: missing expression
old query:
select a.assign_no, a.assign_type, a.act_end, X.ord_no, x.account_no, X.ASSGN_SHIP_DATE, X.ORD_QTY, td.from_loc, sum(td.act_qty) AS ACTQTY, sum(td.exp_qty) AS EXPQTY from clsd_assign a, clsd_task t, clsd_task_detail td, sku s, (SELECT OH.ORD_CNTRL_NO, OH.ORD_NO, OH.ASSGN_SHIP_DATE, oh.account_no, sum(OL.ORD_QTY) AS ORD_QTY
[code]...
new query
select a.assign_no, a.assign_type, TRUNC(A.ACT_END), to_char(a.act_end), X.ord_no, x.account_no, X.ASSGN_SHIP_DATE, X.ORD_QTY, td.from_loc, sum(td.act_qty) AS ACTQTY, sum(td.exp_qty) AS EXPQTY from clsd_assign a, clsd_task t, clsd_task_detail td, sku s where a.act_end between to_char(sysdate -1, 'dd-mon-yyyy') and to_char(sysdate, 'dd-mon-yyyy')
New to using Oracle and SQL Developer. I am trying to subtract a maximum date from today and adding back 1 to get a field named daysSinceLastActivity....
Syntax I am trying is (date()-max(activity_date))+1 as daysSinceLastActivity
I keep getting a error message of missing expression. After googling, I am not finding anything. This should be a simple calculation.
I have a user interface where the user can enter a formula using a set of parameters and operators. For eg , the user is given a list of parameters, say : Width, Height , Gauge. The list of operators include standard math functions : + - / * ^
He can select and create a formula like gauge * width. This is stored in a table. At a later time a job is scheduled to evaluate the formula based on parameters for width, gauge and height.
I can evaluate the expression by substituting each parameter.
I can do this using dynamic sql. However I'm not sure how to evaluate the ^ symbol. The equivalent of this is power function.
So if a user enters (height * 2) + (width^2) . How do i evaluate this. I am doing this in pl/sql.
I am using pipelined functions. I've written a few with no problem this one seems to be giving an error when I am using techniques that appear very similar to ones that work.
I am doing this all in a package;
The type definition is;
TYPE SUSPECT_LINKAGES_FAC_RECORD IS RECORD ( PATIENT_ID TUMOR.TUMOR_PATIENT_ID%TYPE, CENTRAL_SEQ TUMOR.TUMOR_CENTRAL_SEQ%TYPE, MP_REVIEW_FLAG NUMBER(1), FACILITY_FLAG NUMBER );
The variable definition is;
OUT_REC SUSPECT_LINKAGES_FAC_RECORD;
The line with the error is;
PIPE ROW(OUT_REC);
This is the entire function;
FUNCTION GET_SUSPECT_LINKAGE_FAC_FLAGS RETURN SUSPECT_LINKAGES_TABLE PIPELINED AS CURSOR CURS_SUSPECT_LINKAGES IS SELECT * FROM TABLE(TUMOR_UTILITIES.GET_SUSPECT_LINKAGE_FLAGS()) order by 1,2,3 DESC; TEMP_REC SUSPECT_LINKAGES_RECORD; MATCH_COUNT NUMBER; OUT_REC SUSPECT_LINKAGES_FAC_RECORD;
[code].....
I get "PL-00382 expression is of wrong type" on both pipe row (out_rec); lines.
I have an arithmatic expression which is dynamic say
expression = [Col5]/[Col1]
I will be using this in building a dynamic SQL.so i have to make sure that the divisible by zero is taken care. In the expression Col1,Col5 are values coming from a SQL.
I have to build a function which takes in the expression and fetches me the result.My expression can be any combination of arithmaticexpression involving columns.
I ran into a problem recently which has to do with the following query:
SELECT '' || ROUND(GEOGR_LAENGE,5) || ',' || ROUND(GEOGR_BREITE,5) || '," [BUE] ' || BAUFORM_GRUPPE || '"', KM AS TEXT FROM MYTABLEA mmtable WHERE (mmtable.GEOGR_LAENGE IS NOT NULL AND mmtable.GEOGR_BREITE IS NOT NULL AND mmtable.STRECKE_NR IN (
[code].....
The problem is, that Oracle alerts a missing expression at line 4, and highlights the "IS NOT NULL". Personally I don't see that anything is wrong with this line. I think the problems source is somewhere else but I cannot find it.
I'll give you a little bit of background to the script:
What I am trying to achieve is to request the values in the first line with the following conditions:
- mmtable.GEOGR_LAENGE, GEOGR_BREITE must not be empty - rbtable.STRECKE_NR for the requested line (which is similar to mmtable.STRECKE_NR) must have "MITTE" as a value for NL_NAME - mmtable.KM => rbtable.VON_KM - mmtable.KM <= rbtable.BIS_KM
I'm working on Oracle SQL Developer: ODMiner. I keep getting a syntax error with the following code,
CREATE TABLE FINAL_WEBLOG AS select SESSION_DT, C_IP, CS_USER_AGENT, LISTAGG(WEB_LINK, ' ') WITHIN GROUP (ORDER BY C_IP, CS_USER_AGENT) "WEB_LINKS", FROM WEBLOG_VIEWS GROUP BY C_IP, CS_USER_AGENT, SESSION_DT ORDER BY SESSION_DT
I understand if it's the semicolon that is missing after "FROM WEBLOG_VIEWS", but I'm not sure on how I can rephrase it.
I'm trying to match all sentences that contain words starting with given search tokens at least once. For example: if the given search token words are one and two then only sentences like "one plus one is two" should match. And should not match sentences like "one plus three is four". I was able to come up with this but I need a AND condition which I'm unable to get it right.
select count(*) from dual where regexp_like('one plus one is two', '(^|s)one|three', 'i');
Currently this gives a count of 1. But needs to give a count of 0 when the regexp is fixed.
search words : one two
one is less than two -> match two is greater than one -> match onetwo is union of two numbers -> match onetwo is union of 2 numbers -> not a match as 'two' is not at the beginning of a word one is less than three -> not a match as two is not present.