GROUP BY Clause -SQL Devolper error 00904. 00000 -  "%s: invalid identifier

I'm a real novice with SQL and I am having a problem understanding why this doesn't work. Searching the web got me to this forum, but I haven't been able to find a solution. Obviuosly I don't really understand how to use the GROUP BY clause. The SQL works fine without that clause.
As stated in the subject I am getting this error:
ORA-00904: "SORTPLAN": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:   
*Action:
Error at Line: 9 Column: 17
With this SQL statement:
SELECT START_DTM,
END_DTM,
MACHINE_SORT_PROGRAM_NAME as Sortplan,
sum(TOTAL_PIECES_FED_CNT) AS TotalFed
FROM END_OF_RUN
WHERE MODS_DATE BETWEEN '27-Jul-2011' AND '27-Jul-2011'
AND MAIL_OPERATION_NBR =919
AND SITE_ID = 81003
GROUP BY Sortplan
ORDER BY Sortplan;
TIA
Mike

Gary,
Thank you for pointing me in the right direction. There are so many choices here I had a hard time deciding which to use. :)
I tried your suggestion and still got an error. I had thought I didn't need to use aggregate functions on all of the fields. I guess that was wrong, so I changed it. Once I did that the SQL worked fine.
ORA-00979: not a GROUP BY expression
00979. 00000 - "not a GROUP BY expression"
*Cause:   
*Action:
Error at Line: 2 Column: 3
SELECT MACHINE_SORT_PROGRAM_NAME AS Sortplan,
min(START_DTM),
max(END_DTM),
sum(TOTAL_PIECES_FED_CNT) AS TotalFed
FROM END_OF_RUN
WHERE MODS_DATE BETWEEN '27-Jul-2011' AND '27-Jul-2011'
AND MAIL_OPERATION_NBR =919
AND SITE_ID = 81003
GROUP BY MACHINE_SORT_PROGRAM_NAME
ORDER BY Sortplan;
Mike

Similar Messages

  • Dynamic SQL Error -ORA-00904: invalid identifier

    Hello!
    I'm really hoping I can get some fast help on this. In the interest of honesty, this is for a university oracle programming assignment. I've searched everywhere I can for the answer and haven't had any luck.
    Anyway, the problem in a nutshell. I have to write a package to write a text file. The formatting information for the file is held in a table, which has columns to define the various characteristics like justification, padding character and field value.
    RECORDTYPE FIELDNAME FIELDVALUE FIELDSIZE FIELDORDER PADDINGCHAR JUSTIFICATION DATASOURCE
    7 CreditTotal v_credit 10 5 '0' LPAD PROGRAM
    7 RecordType '7' 1 1 ' ' RPAD HARDCODE
    I can build the whole file except this footer. the FieldValue "v_credit" references a variable that has the calculated total of the credit amounts for the file. There are also "v_debit", and "(v_credit-v_debt)" entries.
    My question seems simple... How can I use this VARCHAR2 value from the table, and have it reference the variable within a Dynamic SQL string? If I use the textvalue of the column in the SQL string it gives me the invalid identifier error when it hits the EXECUTE IMMEDIATE statement. There is another row for the header which has "to_char(sysdate,'DDMMYYYY')" in it, and that runs fine. I'm assuming because they are native SQL statements and variables.
    I have tried encapsulating the v_credit in "s, and using dynamica bind variables but had the same problem passing the names to the USING clause.
    The SQL string created by the procedure is: SELECT LPAD(v_credit,10,'0' ) FROM dual
    The full error is:
    ORA-00904: "V_CREDIT": invalid identifier
    ORA-06512: at "BWOOD.PKG_BRIAN", line 108
    ORA-06512: at line 2
    Line 108 is the EXECUTE IMMEDIATE statement
    I would really appreciate someones help! I'm happy to post the procedure I've written, with the caveat that it's sloppy student work and needs cleaning up of all the experimental commented attempts:)
    Edited by: user5426606 on 20-May-2009 03:34 - Added a few more facts.

    Thank you for the fast replies. I'll post a short chunk of code to demonstrate.
    The actual procedure is quite a bit longer, but this should give you the idea.
    PROCEDURE build_dbfile (p_settlement_date IN DATE, p_settlement_key IN VARCHAR2, p_type IN VARCHAR2) AS
    v_sqlString    VARCHAR2(4000) := 'SELECT ';
    v_rectype     NUMBER := 7;
    v_line           LONG;
    v_debit        NUMBER := 0;
    v_credit       NUMBER := 0;
    v_nrRecords    NUMBER := 0;
      CURSOR c_settlement IS... -- to select records for data rows
    -- cursor to select the rows with the file formatting and data info
      CURSOR c_header IS   SELECT   NVL(fieldvalue,fieldname) db_field, <---- selects the data column
                                                   fieldsize,
                                                   NVL(paddingchar, ''' ''') paddingchar,
                                                   NVL(justification,'LPAD') justification,
                                                  datasource
                                      FROM     FSS_DESKBANK_REF
                                      WHERE    recordtype = r_rec_types.recordtype
                                      ORDER BY recordType, fieldorder;
    -- SELECT to get the SUM of datarows for v_credit
      SELECT      SUM(transactionamount)
      INTO      v_credit...
    -- SELECT to get the SUM of datarows for v_debit
      SELECT      SUM(transactionamount)
      INTO      v_debit....
    FOR r_head IN c_header LOOP
    v_sqlString := v_sqlString  || r_head.justification|| '('
                                         || r_head.db_field ||','
                                         || r_head.fieldsize || ','
                                         || r_head.paddingchar || ')';
    v_sqlString := v_sqlString || ' FROM ' || v_tbl_name;
    DBMS_OUTPUT.PUT_LINE('SQL --> '||v_sqlString);
    EXECUTE IMMEDIATE v_sqlString INTO v_line;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE(v_line);
    END build_dbfile;So the loop goes through the table rows, grabs each data value and formatting column, and builds the sql string, which is then passed to the execute statement. The issue is the ones where the datarow contains a reference to v_credit, and the error is generated. ie r_head.db_field contains the string "v_credit"
    Satish, the sql does look like that in the string, but the string is built from the table, not hardcoded. ie v_sqlString = "SELECT LPAD(v_credit,10,'0' ) FROM dual" when it is passed to the EXECUTE IMMEDIATE.
    Edited by: user5426606 on 20-May-2009 05:19

  • Java.sql.SQLSyntaxErrorException: ORA-00904: "GROUPID": invalid identifier

    I have this Oracle table:
    CREATE TABLE USERGROUPS(
      GROUPID INTEGER NOT NULL,
      GROUPNAME VARCHAR2(40 ),
      GROUPSTATUS VARCHAR2(30 ),
      DATEGROUPADDED DATE,
      DATEGROUPLOCKED DATE,
      GROUPEXPIREDATE DATE,
      DESCRIPTION CLOB
    /I tried to run this SQL query:
    SELECT c.*
    FROM
      (SELECT b.*,
        rownum rn
      FROM
        (SELECT a.* FROM USERGROUPS a ORDER BY GROUPID ASC
        ) b
      WHERE rownum <= 5
      ) c
    WHERE rn > 10I get this error message in SQL developer when I run it:
    ORA-00904: "GROUPID": invalid identifier
    00904. 00000 - "%s: invalid identifier"
    *Cause:   
    *Action:
    Error at Line: 5 Column: 25
    I also tested this SQL query:
    SELECT GROUPID FROM USERGROUPS I get this error:
    ORA-00904: "GROUPID": invalid identifier
    00904. 00000 - "%s: invalid identifier"
    *Cause:   
    *Action:
    Error at Line: 1 Column: 7
    Can you help me to fix the problem?

    Are you sure the create table statement executed successfully (with no error)?
    Perhaps you use an older version of the table where the column groupid did not exists.
    You can check the columns of your table with:
    select * from all_tab_columns
    where table_name='USERGROUPS'
      and owner='<schema-name>'
    order by column_id;Another reason could be, that exist two tables with the same name.
    You could check that with
    select *
    from all_tables
    where table_name ='USERGROUPS';hm

  • Quick Migrate from SQL Server error

    I am attempting to migrate my databases from SQL Server 2000 to Oracle 11g. I am attempting to use the quick migrate feature of Oracle SQL Developer and receiving an error, the same error for every database during the build stage. The error is as follows. Any ideas as to resolve this error?
    Error starting at line 2 in command:
    CREATE TABLE EMPLOYEE (
    Error at Command Line:2 Column:23
    Error report:
    SQL Error: ORA-00904: : invalid identifier
    00904. 00000 - "%s: invalid identifier"
    *Cause:   
    *Action:
    Commit
    Oracle 11g on Windows XP and version 1.2.1.32.13 of sql developer
    Brian
    Message was edited by:
    user606370

    We have two more customers that currently are in the process of upgrading from MS SQL but as far as I know no one has actually performed an upgrade this far.
    If you want to upgrade to OIM 9.1 you will have to wait until the upgrade scripts are available (estimated arrival H2 2008 according to the latest info I have).
    If you would like to discuss this further send me an email on firstname.lastname@my_company.com (you can get the "variables" from my forum profile)
    Best regards
    /M

  • Error 00904 trying to alter table ... ?!

    I'm running a script to create a table, the primary key of that table will then be used in an Alter Table command to make it a foreign key in an already exisiting table. Code:
    CREATE TABLE Category
    CATCODE VARCHAR2(3),
    CatDesc VARCHAR2(11) NOT NULL,
    CONSTRAINT Category_CATCODE_pk PRIMARY KEY(CATCODE)
    INSERT INTO Category(CATCODE, CatDesc) VALUES('BUS','Business');
    INSERT INTO Category(CATCODE, CatDesc) VALUES('CHN','Children');
    INSERT INTO Category(CATCODE, CatDesc) VALUES('COK','Cooking');
    INSERT INTO Category(CATCODE, CatDesc) VALUES('COM','Computer');
    INSERT INTO Category(CATCODE, CatDesc) VALUES('FAL','Family Life');
    INSERT INTO Category(CATCODE, CatDesc) VALUES('FIT','Fitness');
    INSERT INTO Category(CATCODE, CatDesc) VALUES('SEH','Self Help');
    INSERT INTO Category(CATCODE, CatDesc) VALUES('LIT','Literature');
    ALTER TABLE books ADD CONSTRAINT books_Category_fk FOREIGN KEY (CATCODE) REFERENCES Category(CATCODE);
    And the error:
    Error starting at line 20 in command:
    ALTER TABLE books ADD CONSTRAINT books_Category_fk FOREIGN KEY (CATCODE) REFERENCES Category(CATCODE)
    Error report:
    SQL Error: ORA-00904: "CATCODE": invalid identifier
    00904. 00000 - "%s: invalid identifier"
    *Cause:
    *Action:
    I have no idea what is wrong with my code. I successfully make my table and insert the data, why is it telling me CatCode is an invalid identifier?...
    ( I originally posted it in the wrong section whoops )

    Zombnom wrote:
    There isn't, I'm trying to ADD a column with CatCode being a foreign key in the books table.Well there's your problem. Column and foreign key are two seperate things. You can combine the two operations though:
    ALTER TABLE books ADD catcode CONSTRAINT books_category_fk REFERENCES category(catcode);

  • Right GROUP BY clause

    I wrote the view in the Original View section below. I query it with the following SELECT statement:
    SELECT *
    FROM ZZBUD_DEBT_SERVICE_V
    WHERE action_month IN ('01','02')
    AND action_year IN ('2011')
    AND short_name IN( 'WHIT-18','2REDFERN')
    ORDER BY action_year,action_month, group1, group2, short_name;
    An get these results:
    SHORT GROUP1 GROUP2 ACTION ACTION CURR CURR CURR
    NAME YEAR MONTH INT INT PRIN
    ACCRUED PAYMENT PAYMENT
    2REDFERN     05     02 2011 01     149.39     0     0     
    2REDFERN     05     02 2011 02     0     896.32 49795.84     
    WHIT-18     05     01 2011 01     442.86     0     0     
    WHIT-18     05     01 2011 02 442.86 2657.14 0     
    I need to compute the year-to-date CURR_INT_ACCRUED, CURR_INT_PAYMENT, CURR_PRIN_PAYMENT (SUM(CURR_INT_ACCRUED), etc.) by short_name and action_year but I can't tweek my GROUP BY statement properly. What would the GROUP BY expression look like to get the sum of these columns?
    Original View:
    CREATE OR REPLACE VIEW ZZBUD_DEBT_SERVICE_V(short_name, group1, group2, action_year, action_month
    , curr_int_acrrued, curr_int_payment, curr_prin_payment)
    AS
    SELECT short_name, group1, group2, action_year, action_month
    , SUM(curr_int_acrrued) curr_int_acrrued
    , SUM(curr_int_payment) curr_int_payment
    , SUM(curr_prin_payment) curr_prin_payment
    FROM (
    SELECT dsa.short_name
    , dsa.group1
    , dsa.group2
    , dsa.action_year
    , dsa.action_month
    , DECODE(SIGN(dsa.int_accrued),-1,0 ,0,0,dsa.int_accrued) curr_int_acrrued
    , DECODE(SIGN(dsa.ytd_accrued),1,0,0,0,ABS(dsa.ytd_accrued)) curr_int_payment
    , DECODE(SIGN(dsa.bond_outstand),1,0,0,0,ABS(dsa.bond_outstand)) curr_prin_payment
    FROM NYC.ZZBUD_DEBT_SERVICE_MASTER DSA
    WHERE dsa.bond_status = 'A'
    AND dsa.group1 IN ('03', '05', '06', '07')
    ORDER BY dsa.group1, dsa.group2, DSA.short_name, dsa.action_year, dsa.action_month
    GROUP BY short_name,group1,group2,action_year,action_month

    It depends on how you look at it. When I issue the command:
    SELECT group1, group2, short_name,SUM(curr_int_acrrued) ytd_accrued_int
    FROM ZZBUD_DEBT_SERVICE_V
    WHERE action_month IN ('01','02')
    AND action_year IN ('2011')
    AND short_name IN ('BXRIVER','WILSON','WHIT-18','2REDFERN')
    GROUP BY action_year,action_month,group1, group2, short_name
    ORDER BY action_year,action_month, group1, group2, short_name
    I'm not getting the results I want as 'WHIT-18' shows detail for both action_months and I want the SUM of 01 & 02 and the same for the other short_names. When I drop columns from the GROUP BY clause I get error ORA-0979 'Not a GROUP BY expression'.

  • Issue in group by clause.

    Hi,
      I am using a select query to retrieve sum of few numeric fields as below.
    select field1 field2
             sum ( field3 ) as field3
             sum ( field4 ) as field4
    into table t_tab1
    from dbtab
    where field1 in s_field1
    and   field2 in s_field2
    and   field <> 'RNIC'
    group by field1 field2.
    above code while syntax check gives error stating field 'RNIC' is missing in group by.
    When I remove group by, program gives a short dump.
    Please help me in resolving this issue.
    Thanks in advance.
    Suresh.

    Hi Rich,
       I am using equals opereator in the select query, if I remove the group by clause, no syntax errors appears but program gives dump saying the table mentioned in from clause does not have any field by 'SUM'. However if I mention group by clause it gives syntax error,
    please suggest....
    Suresh.
    this is my select query.
      SELECT rcomp racct robukrs
             sum ( tslvt ) AS tslvt
             sum ( tsl01 ) AS tsl01
             sum ( tsl02 ) AS tsl02
             sum ( tsl03 ) AS tsl03
             sum ( tsl04 ) AS tsl04
             sum ( tsl05 ) AS tsl05
             sum ( tsl06 ) AS tsl06
             sum ( tsl07 ) AS tsl07
             sum ( tsl08 ) AS tsl08
             sum ( tsl09 ) AS tsl09
             sum ( tsl10 ) AS tsl10
             sum ( tsl11 ) AS tsl11
             sum ( tsl12 ) AS tsl12
        FROM (w-tabnm)  CLIENT SPECIFIED
        INTO TABLE t_zzallt
         WHERE rclnt   EQ syst-mandt
         AND rcomp     IN s_rcomp
         AND racct     IN s_saknr
         AND racct     IN aoacct_range
         AND ( rcomp  NOT IN aononk4rcomp_range )
         AND ryear     EQ p_year
         AND  ( ( rldnr = 'PS' AND rcomp  NOT IN aopsrcompx_range ) OR
                ( rldnr  NOT IN ao_ledgerx_range ) )
       GROUP BY rcomp racct robukrs.

  • Select columns not in group by clause

    Hi Guys,
    I want to fetch columns from a table which are not in group by clause. The catch here is that I also need a count and decode column..
    SELECT col_A, col_B, decode(col_C, '10', '10', '26', '26', '00') col_CT, col_X, col_Y count(*) CNT
    FROM TABLE_T
    WHERE col_B IN (100,101,102) AND col_C IN ('44','45','10','26')
    GROUP BY col_A, col_B, decode(col_C, '10', '10', '26', '26', '00')
    ORDER BY col_CT
    Since, col_X and col_Y are not in GROUP BY clause, it throws error. Also, decode/count of the columns makes it more complex.
    Please help me on this.
    Thanks,
    Amy

    Hi, Amy,
    Welcome to the forum!
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statments, relevant columns only) for all tables involved, and the results you want from that data.
    Always say which versionof Oracle you're using.
    How to do what youy want depends on what you want, which is unclear.
    If you say "GROUP BY a, b, c", that means you only want one row of output for each distinct combination of a, b and c. How do x and y fit into that? Do you want a separate output row for each distinct combination of a, b,c, x and y? Then add x and y to the GROUP BY clause. If you don't want separate rows for each combinataion of x and y, what do you want when a group has more than 1 value for either of them?
    You can simplify the code a little by doing the DECODE in a sub-query; then you can use the alias col_ct as many times as you like in the main query. That will make the code easier to maintain, too.

  • Using indexes when using group by clause

    How can I make use of indexes when there is a group by clause in the sql/ pl/sql. Heard that when ever there is a group by clause , sql bypasses use of indexes. Is it true?
    Thanks in advance

    Hi,
    Depending on the query containing the group by, indexes will still be used.
    For example, create a big table based on the all_objects table. Then create an index on the object_type column. Then run this query:
    select count(*), object_type from big_table where object_type != 'PACKAGE' group by object_type
    The execution plan for this query will show the index to be used, the group by does not prevent the optimizer from using an index. Then run this query:
    select count(*), object_type from big_table group by object_type
    The execution plan for this query will show the index not to be used because the whole table - no restrictions - needs to be read to get the result.
    Hope this helps!
    Regards,
    Marco Stuijvenberg
    =
    www.marcostuijvenberg.nl

  • Error message when compiling invalid packages and procedures

    Hi.
    I have a routine for copying certain data from a production database to a test database. To do this I disable constraints and triggers, truncate tables, copy tables and enable triggers and constraints again.
    Now several of my functions, procedures and packages are made invalid and marked with a red cross. In SQL Developer I can compile invalid functions, procedures and packages. When I compile functions it works fine, but when compiling procedures and packages I get the following error message:
    An error was encountered performing the requested operation:
    ORA-00904: "ATTRIBUTE": Invalid identifier
    Vendor code 904
    When I click OK on this message I get a confirmation saying:
    Packages have been compiled with #0.CNT# errors.
    I had this error in both the previous and the new version. Is this a bug or is there a way to come around it? When I copy and modify the SQL generated to perform this task and run it in SQL Plus it works fine.
    I use Windows 2000 5.00.2195 Service Pack 4, SQL Developer version 1.2.1, Oracle 9.2.0.8.0 and Java version 1.5.0_11
    Message was edited by:
    SvSig

    i have now upgraded to Java 1.6 update 2. I still get basically the same error, but it is presented a little bit differently:
    An error was encountered performing the requested operation:
    ORA-00904: "ATTRIBUTE": invalid identifier
    00904. 00000 - "%s: invalid identifier"
    *Cause:
    *Action:
    Vendor code 904
    Are there other possible error causes than the operating system version and the database version?
    We are going to install an Oracle 10 test database in a couple of weeks, so then I will find out whether the database version is the problem.

  • SQL Developer Abrupt behaviour -- Invalid Identifier

    I have tried to use below 2 SQL using Script output (F5) both of them are semantically incorrect, but first one give no error, while second one give error
    SELECT substr(argument,1,2) FROM DUAL WHERE XX_ID LIKE 'XX';
    No error raised.
    SELECT argument FROM DUAL WHERE XX_ID LIKE 'XX';
    Error starting at line 1 in command:
    SELECT argument FROM DUAL WHERE XX_ID LIKE 'XX'
    Error at Command Line:1 Column:33
    Error report:
    SQL Error: ORA-00904: "XX_ID": invalid identifier
    00904. 00000 - "%s: invalid identifier"
    *Cause:   
    *Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Hi Shahid,
    I tried the same in 3.1.07.42 using jdk1.6.0_31:
    Worksheet
    SELECT substr(argument,1,2) FROM DUAL WHERE XX_ID LIKE 'XX';
    SELECT argument FROM DUAL WHERE XX_ID LIKE 'XX';Run Script -> Script Output
    Error starting at line 1 in command:
    SELECT substr(argument,1,2) FROM DUAL WHERE XX_ID LIKE 'XX'
    Error at Command Line:1 Column:44
    Error report:
    SQL Error: ORA-00904: "XX_ID": invalid identifier
    00904. 00000 -  "%s: invalid identifier"
    *Cause:   
    *Action:
    Error starting at line 2 in command:
    SELECT argument FROM DUAL WHERE XX_ID LIKE 'XX'
    Error at Command Line:2 Column:32
    Error report:
    SQL Error: ORA-00904: "XX_ID": invalid identifier
    00904. 00000 -  "%s: invalid identifier"
    *Cause:   
    *Action:Maybe your SQL Developer version is different? Or you really got both errors, but the sizing of your Script Output tab only displayed the last one and you didn't notice the scroll bar at the tab's right side?
    Regards,
    Gary
    SQL Developer Team

  • Why can't i create a GLOBAL TEMP      ORA-00904:string: invalid identifier

    I have the following error see error message beneath.
    The error message states that -> The column name entered is either missing or invalid.
    But what is wrong with the column name that i have?
    Error starting at line 815 in command:
    CREATE GLOBAL TEMPORARY TABLE tt_v_Table
    rownum NUMBER(10,0) PRIMARY KEY NOT NULL, /* this is line 815*/
    TestTableID NUMBER(10,0)
    Error at Command Line:817 Column:2
    Error report:
    SQL Error: ORA-00904: : invalid identifier
    00904. 00000 - "%s: invalid identifier"
    *Cause:   
    *Action:
    Warning: execution completed with warning
    TRIGGER tTestTableUpd Compiled.
    Message was edited by:
    user640306

    By the way the code was generated with Oracle SQL Developer migration functionality (client-only) 1.5.0.53.04
    I am migrating a MS SQL 2005 database to an Oracle 9i database. I have the following installed:
    • Oracle 9i Enterprise Edition Release 9.2.0.1.0 –Production with the partitioning, Spatial, Olap, and Oracle data mining options.
    • Internal to Oracle SQL Developer (client-only) 1.5.0.53.04
    • JTDS JDBC Driver 11.4.4.53.01 oracle.sqldeveloper.thirdparty.drivers.sqlserver
    • Java(TM) Platform 1.5.0_06
    Message was edited by:
    user640306

  • Report parameters being passed in URL - invalid identifier error

    Hi
    Id anyone aware of any format in which we should be passing values in the url to the report deployed on the server?
    A parameter that takes in the format 'e123','e234' - example for emp_id parameter.
    If we pass in this form, even a single value as 'e123' in the url to run the report -
    The value e123 is taken in single quotes and it displays the error
    REP-300: "e123": invalid identifier
    That is, it displays the error as if the string was entered in double quotes.

    Hi, Aaron.
    I tried what you said, and my code wouldn't parse correctly. Let me show you the whole module of PL/SQL that I'm dealing with here. I did not write this. This is something I'm maintaining and updating. The part that chokes is near the bottom.
    declare
    l_sql varchar2(4000) := 'select user_name,total from (select user_name,count(*) total from eba_ver2_cust_activity ' ;
    begin
    if :P23_START_DATE is not null and :P23_END_DATE is not null then
    l_sql := l_sql || ' where ACTIVITY_DATE between ''' || to_char(to_date(:P23_START_DATE,'dd-mon-yyyy'),'dd-mon-yyyy')
    || ''' and ' || '''' || to_char(to_date(:P23_END_DATE,'dd-mon-yyyy') ,'dd-mon-yyyy') || '''' ;
    elsif :P23_START_DATE is not null then
    l_sql := l_sql || ' where ACTIVITY_DATE >= ''' || to_char(to_date(:P23_START_DATE,'dd-mon-yyyy'),'dd-mon-yyyy') ||
    elsif :P23_END_DATE is not null then
    l_sql := l_sql || ' where ACTIVITY_DATE <= ''' || to_char(to_date(:P23_END_DATE,'dd-mon-yyyy'),'dd-mon-yyyy') || ''''
    end if;
    if :P23_ACTIVITY_TYPE != '%null%' and :P23_ACTIVITY_TYPE is not null then
    if :P23_START_DATE is not null or :P23_END_DATE is not null then
    l_sql := l_sql || ' and activity_type_id = ' || :P23_ACTIVITY_TYPE ;
    else
    l_sql := l_sql || ' where activity_type_id = ' || :P23_ACTIVITY_TYPE ;
    end if;
    end if;
    l_sql := l_sql || ' group by user_name )' ;
    return l_sql ;
    end ;
    I appreciate all the help. As for the job market for Apex programmers around here, I wouldn't know. I was a COBOL programmer for many years. I'm approaching retirement, and this will probably be my last IT job.
    Steve "the n00b" in Raleigh NC

  • ORA-00904 - invalid identifier when adding new column to the report query

    Hi,
    I am trying to add a new field to an existing bespoke report query. When I click on ok, I get the following error
    message: "ORA-00904: <field name> : invalid identifier ==> <field_name>
    Any ideas what is causing this problem? Version of the report builder is : 6.0.8 and is connected to a 10.2 db.
    Any help appreciated.
    Many Thanks,
    Praveen
    Edited by: praveenrn on May 21, 2009 2:38 PM

    What is the field name ? Maybe a reserved word ? Change to "my_new_variable" to check...
    Cheers,
    Jens Rettig

  • -- SQL -- GROUP BY clause: non-aggregate fields mandate

    Hello,
    I was studying Databases, (particularly the retrieval of the data), and found something interesting.
    While using an Aggregate Function in the SELECT clause, it is mandatory to have all the non-aggregate fields in the SELECT clause to be there in the GROUP BY clause.
    For example,
    SELECT dept_no, SUM(salary)
    FROM employee
    GROUP BY dept_no;
    The above SQL works fine.
    But, what if the user misses the dept_no in the GROUP BY clause or he/she misses the GROUP BY clause itself?
    Certainly, it is an error.
    Why is this error not handled by the database. I mean, the database should be smart/intelligent enough to add the GROUP BY clause by itself. So suppose, if I miss out the GROUP BY clause or miss a non-aggregate field from the SELECT clause when I am having at least one aggregate function on a field with at least one non-aggregated field in the SELECT clause, the database should check the GROUP BY clause at time of compilation and add the mandate missed out fields in the GROUP BY clause.
    Example,
    SQL1:_
    SELECT dept_no, SUM(salary)
    FROM employee
    GROUP BY dept_no;
    SQL2:_
    SELECT dept_no, SUM(salary)
    FROM employee;
    Here, the SQL1 and SQL2, both should give me same outputs without an error.
    I am unable to understand why is this not handled?

    Hi,
    998478 wrote:
    ... If we mix aggregate and non-aggregate values then there must be a GROUP BY clause containing all the non-aggregate values. Why is this not handled by the database/compiler itself? It IS handled by the compiler itself. The compiler handles it by raising an error. The compiler has no way of knowing whether you want to remove something from the SELECT clause, or to add something to the GROUP BY clause, or not to use aggregate functions, or to use more aggregate functions, or some combination of the above. If the compiler re-wrote your code, and did any of these things automatically, it would be wrong more often than it was right, and you would (rightly) be complaining about its behavior.
    For example, this is clearly wrong:
    SELECT    deptno
    ,       job
    ,       SUM (sal)
    FROM       scott.emp
    GROUP BY  deptno
    ;What is the right way to fix it?
    <h3>1. Remove something from the SELECT clause</h3>
    SELECT    deptno
    ,       SUM (sal)
    FROM       scott.emp
    GROUP BY  deptno
    ;<h3>2. Add something to the GROUP BY clause</h3>
    SELECT    deptno
    ,       job
    ,       SUM (sal)
    FROM       scott.emp
    GROUP BY  deptno
    ,         job
    ;<h3>3. Not use aggregate functions</h3>
    SELECT    deptno
    ,       job
    ,       sal
    FROM       scott.emp
    ;<h3>4. Use more aggregate functions</h3>
    SELECT    deptno
    ,       MIN (job)
    ,       SUM (sal)
    FROM       scott.emp
    GROUP BY  deptno
    ;These aren't all the options, either. For example, the correct fix might be to use analytic functions instead of aggregate functions.
    How can anybody say which of these is right? All of them are the right answer for some problem.
    By the way, saying that everying in the SELECT clause must be an aggregate or in the GROUP BY clause is a bit over-simplified.
    More completely, here 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')").
    Edited by: Frank Kulash on Apr 13, 2013 1:44 PM
    Added code examples.

Maybe you are looking for

  • Date and Time in Sender File Adapter Target Directory

    Hi there, is there a way of using Date and Time from XI to the Target Directory naming? To use variable substitution some fields of the message had to contain that date and time information, which is not our case. For filename you can use "add time s

  • Problem with database connection in Jdev 11

    Hello, my jdev version is 11 and i want do really simple task create new database connection to my oracle db. I open database navigator and click new connection. i want jdbc connection but after i fill this form i pressed test connection button and g

  • Background job not working for VF02

    Hi, When i give schedule RSNAST00 report in background for one output type its not generating spool, but the job status is in Complete. But in foreground it fine. For another output type its working fine in background. Is there any printer setting ha

  • How to use IDOC and RFC adapter in 1 scenario?

    We have AAA field and BBB field and we want to send AAA field to receiver sap system using IDOC adapter and BBB field to receiver sap system using RFC adapter. But how to use IDOC and RFC adapter in 1 scenario and how to map and  what are the design

  • How to migrate call & SMS filter numbers from old ...

    As the title says...I have an old 720 with loads of blocked/filtered numbers and I want to transfer them to my new dual sim 630 as blocked/filtered numbers. Possible? If not it needs to be since I will have to endure exactly the spam I already did in