INVALID IDENTIFIER error in SEQUEL statement

I'm having trouble with this SELECT statement in a report with search items. The search item in Question is the string "Email." Any activity record that has "Email" in the activity_type field is to be selected. The line of code is:
select user_name,total from (select user_name,count(*) total from eba_ver2_cust_activity where activity_type = Email group by user_name )
order by 2 desc,2 desc
There are some substitutions in here. The value "Email" is from :P23_ACTIVITY_TYPE on the page.
The error I get is:
failed to parse SQL query:
ORA-00904: "EMAIL": invalid identifier
The problem is that the String constant is being interpreted as an identifier name. Some sbustitutions are made to general the SELECT statement that fails. The relevant portion of the code generating the erroneous SELECT is:
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;
Either way, the contents of :P23_ACTIVITY_TYPE are treated as an identifier instead of a string. Please help.
Steve "the n00b" in Raleigh NC

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

Similar Messages

  • IKM MTI , invalid identifier error

    Hi,
    I am using employees table as my source and inserting data into employees_1,employees_2 and employees_3 target tables using IKM Multi Table insert.
    I get an invalid identifier error on insert new rows step of the last interface:-
    ODI-1228: Task INT_EMP3 (Integration) fails on the target ORACLE connection TARGET.
    Caused By: java.sql.SQLSyntaxErrorException: ORA-00904: "C11_DEPARTMENT_ID": invalid identifier
    Usually this error occurs when there is a type mismatch. I have checked the data type but there is no mismatch.
    The code generated is :-
    insert all
    when 1=1 then
    into TARGET.EMPLOYEES_1
    (EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE, JOB_ID, SALARY, COMMISSION_PCT, MANAGER_ID, DEPARTMENT_ID)
    values
    (C1_EMPLOYEE_ID, C2_FIRST_NAME, C3_LAST_NAME, C4_EMAIL, C5_PHONE_NUMBER, C6_HIRE_DATE, C7_JOB_ID, C8_SALARY, C9_COMMISSION_PCT, C10_MANAGER_ID, C11_DEPARTMENT_ID)
    when 1=1 then
    into TARGET.EMPLOYEES_2
    (EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE, JOB_ID, SALARY, COMMISSION_PCT, MANAGER_ID, DEPARTMENT_ID)
    values
    (C1_EMPLOYEE_ID, C2_FIRST_NAME, C3_LAST_NAME, C4_EMAIL, C5_PHONE_NUMBER, C6_HIRE_DATE, C7_JOB_ID, C8_SALARY, C9_COMMISSION_PCT, C10_MANAGER_ID, C11_DEPARTMENT_ID)
    when 1=1 then
    into TARGET.EMPLOYEES_3
    (EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE, JOB_ID, SALARY, COMMISSION_PCT, MANAGER_ID, DEPARTMENT_ID)
    values
    (C1_EMPLOYEE_ID, C2_FIRST_NAME, C3_LAST_NAME, C4_EMAIL, C5_PHONE_NUMBER, C6_HIRE_DATE, C7_JOB_ID, C8_SALARY, C9_COMMISSION_PCT, C10_MANAGER_ID, C11_DEPARTMENT_ID)
    select     
         C1_EMPLOYEE_ID EMPLOYEE_ID,
         C2_FIRST_NAME FIRST_NAME,
         C3_LAST_NAME LAST_NAME,
         C4_EMAIL EMAIL,
         C5_PHONE_NUMBER PHONE_NUMBER,
         C6_HIRE_DATE HIRE_DATE,
         C7_JOB_ID JOB_ID,
         C8_SALARY SALARY,
         C9_COMMISSION_PCT COMMISSION_PCT,
         C10_MANAGER_ID MANAGER_ID,
         C11_DEPARTMENT_ID DEPARTMENT_ID
    from     ODI_WORK_PRERNA.C$_0EMPLOYEES_1
    where     (1=1)
    When i run this code at the back end after removing the column alias from the select statement, the query works fine. Otherwise it throws the same error at the backend as well.
    Please let me know how to resolve this issue.
    Thanks,
    Prerna
    P.S. For now i modified the km to generate a query without column alias and the interface is working fine. But i want to know why am i getting this error with the column alias.

    If you see the insert statement the values you are defining are C1_column_name:
    into TARGET.EMPLOYEES_1
    (EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, PHONE_NUMBER, HIRE_DATE, JOB_ID, SALARY, COMMISSION_PCT, MANAGER_ID, DEPARTMENT_ID)
    values
    *(C1_EMPLOYEE_ID, C2_FIRST_NAME, C3_LAST_NAME, C4_EMAIL, C5_PHONE_NUMBER, C6_HIRE_DATE, C7_JOB_ID, C8_SALARY, C9_COMMISSION_PCT, C10_MANAGER_ID, C11_DEPARTMENT_ID)*
    But when you are selecting data the alias names are different :
    select     
    C1_EMPLOYEE_ID EMPLOYEE_ID,
    C2_FIRST_NAME FIRST_NAME,
    C3_LAST_NAME LAST_NAME,
    C4_EMAIL EMAIL,
    C5_PHONE_NUMBER PHONE_NUMBER,
    C6_HIRE_DATE HIRE_DATE,
    C7_JOB_ID JOB_ID,
    C8_SALARY SALARY,
    C9_COMMISSION_PCT COMMISSION_PCT,
    C10_MANAGER_ID MANAGER_ID,
    C11_DEPARTMENT_ID DEPARTMENT_ID
    from     ODI_WORK_PRERNA.C$_0EMPLOYEES_1
    where     (1=1)
    It is a SQL problem. There is another example you can check i.e.
    Select Employee_id from ( select employee_id c1_employee_id from employees);
    When Employee_ID comes to the outer query its name is changed to c1_employee_id , so this sql will give you same error as invalid identifier.
    Change the IKM again and provide same names or even remove the alias.
    Hope it helps

  • Dynamic SQL Issue ORA-00904:invalid identifier error

    Here is my SP
    create or replace procedure srini_ref_cursor_test(p_county_code IN VARCHAR2,
    p_ref_cur out PK_FR_TYPES.cursor_type) is
    query_str varchar2(5000);
    begin
    query_str := 'SELECT * FROM dw_county where county_name = :P ';
    open p_ref_cur for query_str USING p_county_code;
    insert into srini_query_str_test values (query_str);
    commit;
    end srini_ref_cursor_test;
    When I pass the p_county_code = Adams working find.
    create or replace procedure srini_ref_cursor_test(p_county_code IN VARCHAR2,
    p_ref_cur out PK_FR_TYPES.cursor_type) is
    query_str varchar2(5000);
    begin
    query_str := 'SELECT * FROM dw_county where county_name in ('||p_county_code||')';
    open p_ref_cur for query_str;
    insert into srini_query_str_test values (query_str);
    commit;
    end srini_ref_cursor_test;
    When I pass the p_county_code = Adams for above SP I got the following error
    ORA-00904: "ADAMS": invalid identifier error
    With out Bind variables how Can I pass the Char type values in Dynamic SQL ?
    I would like to pass multipule values to p_county_code like 'Adams','Ashley' etc
    How Can I do this ?
    Thank for great help.
    Srini

    How do I write the Dynamic SQL for
    SELECT * FROM DW_COUNTY WHERE COUNTY_NAME LIKE 'Ad%'
    The usual way...
    hr@ORA10G>
    hr@ORA10G> var str varchar2(1000);
    hr@ORA10G> var cr refcursor;
    hr@ORA10G>
    hr@ORA10G> exec :str := 'select * from employees where first_name like ''A%''';
    PL/SQL procedure successfully completed.
    hr@ORA10G> -- note the escape character for each single quote
    hr@ORA10G> print str
    STR
    select * from employees where first_name like 'A%'
    hr@ORA10G>
    hr@ORA10G> exec open :cr for :str;
    PL/SQL procedure successfully completed.
    hr@ORA10G> print cr
    EMPLOYEE_ID FIRST_NAME           LAST_NAME                 EMAIL                     PHONE_NUMBER      HIRE_DATE JOB_ID    SALARY COMMISSION_PCT MANAGER_ID DEPARTMENT_ID
            103 Alexander            Hunold                    AHUNOLD                   590.423.4567         03-JAN-90 IT_PROG          9000                       102            60
            115 Alexander            Khoo                      AKHOO                     515.127.4562         18-MAY-95 PU_CLERK         3100                       114            30
            121 Adam                 Fripp                     AFRIPP                    650.123.2234         10-APR-97 ST_MAN           8200                       100            50
            147 Alberto              Errazuriz                 AERRAZUR                  011.44.1344.429278   10-MAR-97 SA_MAN          12000             .3        100            80
            158 Allan                McEwen                    AMCEWEN                   011.44.1345.829268   01-AUG-96 SA_REP           9000            .35        146            80
            167 Amit                 Banda                     ABANDA                    011.44.1346.729268   21-APR-00 SA_REP           6200             .1        147            80
            175 Alyssa               Hutton                    AHUTTON                   011.44.1644.429266   19-MAR-97 SA_REP           8800            .25        149            80
            185 Alexis               Bull                      ABULL                     650.509.2876         20-FEB-97 SH_CLERK         4100                       121            50
            187 Anthony              Cabrio                    ACABRIO                   650.509.4876         07-FEB-99 SH_CLERK         3000                       121            50
            196 Alana                Walsh                     AWALSH                    650.507.9811         24-APR-98 SH_CLERK         3100                       124            50
    10 rows selected.
    hr@ORA10G>
    hr@ORA10G>pratz

  • Invalid Identifier error in Discoverer Workbook

    Hi All,
    I have created a workbook in Discoverer desktop containing 2 worksheets(2 Reports)in it.
    After creating the first report I ran it and able to see the out put.
    Then created the 2nd report and successfully gave the output.
    After that if i switch to the first report(1st sheet) in the workbook it gives "ORA:09004 Invalid Identifier" Error and I am not able to run the report.
    Then i closed the workbook and tried reopening. But that time it gives the following error,
    "Unable to find the error text for this exception"
    "Attempt to open workbook failed"
    I have saved the workbook in the database.
    Can anyone tell me what is the cause for this error? What is the solution for this errors? Whether the workbook will be lost permanently?
    Thanks
    Alaka

    Hi,
    What is "m_Xml" ?
    Give us something we can use to reproduce the issue.
    The query you gave cannot be run.
    (btw, tags must be in lowercase)                                                                                                                                                                                                                                                                                                                           

  • Invalide identifier error, when use subselect

    Hi all,
    I got "ORA-0094: sp.spriden_pidm invalid identifier "error when runing the following query.
    select (select t.name from
    (select rownum row_number, s.spriden_last_name name
    from spriden s
    where s.spriden_pidm = sp.spriden_pidm) t
    where t.row_number = 1) last_name
    from spriden sp
    where sp.spriden_pidm = 70105;
    Any one has an idea why this is happening?
    Thanks

    Unless I am missing something here, this looks like a straight pivot query to me.
    SQL> with my_test AS (SELECT 1 id, 'June' contact_name FROM dual UNION ALL
      2                   SELECT 1, 'Email' FROM dual UNION ALL
      3                   SELECT 1, 'Mark' FROM dual UNION ALL
      4                   SELECT 2, 'Tom' FROM dual),
      5       my_test_2 AS (SELECT 1 id, trunc(sysdate) act_date FROM dual UNION ALL
      6                     SELECT 1, trunc(sysdate-1) FROM dual UNION ALL
      7                     SELECT 2, trunc(sysdate-1) FROM dual)
      8  SELECT id, act_date,
      9         MAX(DECODE(rn, 1, contact_name)) nc1,
    10         MAX(DECODE(rn, 2, contact_name)) nc2,
    11         MAX(DECODE(rn, 3, contact_name)) nc3
    12  FROM (SELECT m.id, contact_name, act_date,
    13               ROW_NUMBER() OVER (PARTITION BY m.id
    14                                  ORDER BY contact_name) rn
    15        FROM my_test m, my_test_2 m2
    16        WHERE m.id = m2.id and
    17              m2.act_date = trunc(sysdate-1))
    18  GROUP BY id, act_date;
            ID ACT_DATE    NC1   NC2   NC3
             1 11-Sep-2008 Email June  Mark
             2 11-Sep-2008 TomAssuming that you have a known maximum number of possible values in my_test for a given id this should work. You may need to use something other than the contact_name in the order by in the row_number function if you require the values in specific columns, but given your sample data, I have no idea what that might be.
    John

  • Why do I get a "DATE1 : ORA-00904 Invalid identifier" error ?

    Hi,
    Despite my efforts, I can't see why I get a "DATE1 : ORA-00904 Invalid identifier' error whith this request.
    {code}With S1 as (
    SELECT TRUNC(DATE1, 'MM'),
    ROUND(SUM(VALEUR), 2)
    FROM EVV_E036
    GROUP BY TRUNC(DATE1, 'MM')
    ORDER BY TRUNC(DATE1, 'MM'))
    SELECT n,
    NVL(ROUND(SUM(Valeur),2), 0)
    FROM (select add_months(to_date('01/01/2006', 'dd/mm/yyyy'), level - 1) n FROM dual connect by level <= 12) months
    LEFT JOIN S1
    ON months.n = TRUNC(DATE1, 'MM')
    GROUP BY n
    ORDER BY n{code}
    The line in error is this one : {code}ON months.n = TRUNC(DATE1, 'MM'){code}
    Any idea much appreciated !
    Regards,
    Christian

    hi,
    I have done this and get no more errors. Now I see that the values I get are equal to 0. Or, I do get values different from 0 in my table ! I can't see why the left join gives 0. I have to dig this and come back tomorrow.
    With S1 as (
    SELECT TRUNC(DATE1, 'MM') Date1,
           ROUND(SUM(VALEUR), 2) Debit
    FROM   EVV_E036
    WHERE  CLEF_VAR = (SELECT CLEF_VAR FROM SITE_ECHELLE WHERE SITE = 'E036')
    AND    DATE1 BETWEEN TO_DATE ('01/01/2007000000', 'DD/MM/YYYYHH24MISS') AND TO_DATE ('31/12/2007235959', 'DD/MM/YYYYHH24MISS')
    GROUP  BY TRUNC(DATE1, 'MM')
    ORDER  BY TRUNC(DATE1, 'MM'))
    SELECT n,
           NVL(ROUND(SUM(Debit),2), 0)
    FROM   (select add_months(to_date('01/01/2006', 'dd/mm/yyyy'), level - 1) n FROM dual connect by level <= 12) months
    LEFT JOIN S1
         ON months.n = date1
    GROUP BY n
    ORDER BY n

  • Invalid identified error in procedure

    hi
    I have a package that has a declare variable ,vfilename. I set the value of the variable vfilename to a file name for eg 'abc.txt' when the package scenario is callled. Now this file is the source for an interface that loads from this file to a target table. The interface has source datastore resource defined as a variable.
    After running this interface a procedure is called that will update a metadata table where the record has file_name col value=vfilename.
    to do this in the ODI procedure I am calling a plsql procedure as below
    Begin
    update_load_status(#vfilename)
    end;
    When this procedure runs I get an error as below
    904 : 42000 : java.sql.SQLException: ORA-00904: "abc"."TXT": invalid identifier
    If I call the procedure by hard coding the value i.e update_load_status('abc.txt'). It works fine.
    I have tried concat etc but still the value is not getting passed correctly and I am getting the invalid identified error. Is there a way to get around this?

    If you are saying this code -update_load_status('abc.txt'). work
    then call the variable this way
    Begin
    update_load_status('#vfilename');
    end;

  • Multi-row sub query returns  ORA-00904 :invalid identifier error

    I am creating a report from two tables that I am not joining. I want a single line for every row in table1 that meets a date range. Table2 can contain none or many rows for each recored in table1. I want to get up to two fields from table2.
    I was using a case statement to check if there was data and then an in-line query or subquery. Once again, the idea is to have a single line on the report for each table1 record.
    I get this error with the code below. It seems the nested multi-row subquery can not see the a.cr_mas_cr_no identifier.
    ORA-00904: "a"."cr_mas_cr_no": invalid identifier
    Any help is greatly appreciated,
    Sam
    select
    a.cr_mas_cr_no "CRNO", a.cr_mas_type "TYPE", a.cr_mas_status "CR Status",
    a.cr_mas_date_logged "Logged date", a.CR_REL_REQ_APP_DATE "RTP approved",a.CR_REL_REQ_RTP_DATE "RTP Date",
    a.cr_accepted_date "Complete", a.cr_mas_submitted_by "Requester",
    select doc_user FROM crrm_cr_documents WHERE doc_cr_number =a.cr_mas_cr_no and rownum = 1 and DOC_TYPE = 'BD' ) "Bus Design",
    (select doc_user FROM crrm_cr_documents WHERE doc_cr_number = a.cr_mas_cr_no and rownum = 1 and DOC_TYPE = 'TD' ) "Tech Design",
    (select doc_user FROM crrm_cr_documents WHERE doc_cr_number = a.cr_mas_cr_no and rownum = 1 and DOC_TYPE = 'TE' ) "User acceptance test",
    case
    when (select count(appr_user) from crrm_cr_approvals where appr_cr_no = a.cr_mas_cr_no and appr_type = 'RTP') > 0
    then (select appr_user from (select * from crrm_cr_approvals where appr_cr_no = a.cr_mas_cr_no and appr_type = 'RTP') where rownum = 1)
    end
    "RTP #1",
    case
    when (select count(appr_user) from crrm_cr_approvals where appr_cr_no = a.cr_mas_cr_no and appr_type = 'RTP') > 1
    then (select appr_user from (select * from crrm_cr_approvals where appr_cr_no = a.cr_mas_cr_no and appr_type = 'RTP') where rownum = 2)
    end
    "RTP #2",
    a.CR_REL_REQ_RTP_BY "Released by",
    a.CR_ACCEPTED_BY "Post RTP User Acceptance",
    a.cr_mas_title "Title", a.cr_mas_id "ID"
    from
    crrm_crmaster a
    where
    (a.CR_REL_REQ_RTP_DATE >= :P1109_BEGDATE and (a.CR_REL_REQ_RTP_DATE <= :P1109_ENDDATE) and
    (a.cr_mas_status = 'Complete' or (a.cr_mas_status = 'Release Approved'and a.CR_REL_REQ_APP_DATE < :P1109_ENDDATE))
    Message was edited by:
    slavanaway

    Iceman,
    Thanks for the reply I will try your suggestion.
    I will try and explain why I think two subqueries (an in-line query with a subquery?) are required. I will use the creation of the column RTP #1 as the example as the RTP #2 column is only different in the rownum selected.
    Looking only at the lines that fail, here is my analysis. (If I rem out the two case lines the query runs, I just don't get two columns of data I need.) I will only examine the first case as the second is changed to extract the second approval via the rownum = 2 criteria. The first statement checks there is at least one RTP approval stored for the request and then gets the user who approved the request if the test is true.
    case when
    (select count(appr_user) from crrm_cr_approvals where appr_cr_no =a.cr_mas_cr_no and appr_type = 'RTP') > 0
    then
    The above part works fine and the correct count of approvals is returned.
    (select appr_user from (select * from crrm_cr_approvals where appr_cr_no=a.cr_mas_cr_no and appr_type = 'RTP') where rownum = 1)
    end
    "RTP #1",
    I moved the parenthesis to the correct location. There can be multiple approvals for a given parent record. Some parent records need one, some need two approvals. If I replace
    (select appr_user from (select * from crrm_cr_approvals where appr_cr_no =a.cr_mas_cr_no and appr_type = 'RTP') where rownum = 1)
    with
    (select appr_user from approvals where appr_cr_no =a.cr_mas_cr_no and appr_type = 'RTP' and rownum = 1)
    The correct result is returned because it returns exactly one row as rownum=1 limits the query. When rownum = 2 then the query returns null as the rownum never gets to two as the rownum column is built via the set created by the second subquery.
    The subquery builds a set of approvals for a specific "cr_no" and appr_type of "RTP". the outer query then looks at the rownum of the second query
    Here is where I got the rownum information from;
    http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
    So here is what I think is happening;
    1. Main query From and Where are processed. This should provide the "set" for the query
    2.The from subqueries for RTP #1 and RTP #2 should be able to access the a.cr_mas_cr_no field and build a set from the approvals table.
    3.The RTP #1/2 subquery (inline maybe a better description?) would then get the correct row from the from subquery.
    The error "invalid identifier" refers to the a.cr_mas_cr_no field. I assume it means it can not resolve the table alias inside the subquery.
    So maybe your grouping would help, I will try.
    Sam

  • Invalid Number Error in Merge Statement

    Hi all.
    I got an invalid number error in the following merge statement, but I don't know why. Maybe you can give me a hint.
    MERGE INTO wam_table
    USING (SELECT * FROM wam_table) b
    ON (b.username = 'user'
    AND b.mod = 'module'
    AND b.trimester = '1')
    WHEN MATCHED THEN
    UPDATE SET as = '1', ad = '1', co = '1', pr = '1', date = localtimestamp, lus = 'username'
    WHEN NOT MATCHED THEN
    INSERT VALUES ('user','module','1','1','1','1','1', localtimestamp, 'username');
    The invalid number error appears in the first line, but I don't know why?
    Stephan

    UPDATE SET as = '1', ad = '1', co = '1', pr = '1', date = localtimestamp, lus = 'username'SELECT * FROM sys.v_$reserved_words;
    SQL> create table test1(as varchar2(10));
    create table test1(as varchar2(10))
    ERROR at line 1:
    ORA-00904: : invalid identifier
    SQL> create table test1(sno number, date date);
    create table test1(sno number, date date)
    ERROR at line 1:
    ORA-00904: : invalid identifier
    SQL> create table test1("as" varchar2(10));
    Table created.
    SQL>
    SQL> create table test2(sno number, "date" date);
    Table created.
    SQL> desc test1
    Name                                      Null?    Type
    as                                                 VARCHAR2(10)
    SQL> desc test2
    Name                                      Null?    Type
    SNO                                                NUMBER
    date                                               DATE
    SQL> 

  • 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

  • Invalid identifier error in executing a ref cursr

    I am getting ORA00904: "MARKETING": invalid identifier ... and it's driving me crazy!!
    here's my sql code...
    StrTitle varchar2(500);
    TYPE RefCurCusts IS REF CURSOR;
    rec_ref_custs RefCurCusts;
    strCusts varchar2(500);
    StrTitle := 'MARKETING';
    OPEN rec_ref_custs FOR
    'Select distinct b.account_number, b.marketing_rep_name, c.customer_name, a.meter, a.mappole, a.feeder, b.last_or_corp_name, b.house_number, b.street_direction, b.street_name, b.street_suffix, max(odate) over (partition by b.account_number) last_called, n.message_type, c.list_name     
    From srs.current_outage_calls o, tlm.customer_electric b, srs.notification_list n, SRS.NOTIFIABLE_CUSTOMERS_VW c, srs.est_customer_outages a
    Where c.SERVICE_ADDR_NUMBER = b.SERVICE_ADDR_NUMBER And substr(b.meter_number, 2, 6) = a.meter and b.service_point_end_date is null and o.meter(+)=a.meter and n.list_name=c.list_name and c.list_name = '||StrTitle;
                   LOOP
                        FETCH rec_ref_custs INTO strCusts;
                        EXIT WHEN rec_ref_custs%NOTFOUND;
                             StrBodyHTML:= StrBodyHTML || ', ' || strCusts;
                   END LOOP;
    CLOSE rec_ref_custs;     
    please help!
    Thanks

    Fuse_5a wrote:
    I am taking the value of StrTitle (I changed the name of it to strList in the below code) from a different select statement ... therefore, strList will be changing based on the results of the first query.
    this code is for an automailer that will run every minute!!
    here's more of my code to better explain it ...
    Any suggestions?
    OPEN rec_ref_list FOR
    'Select
    distinct c.list_name     
    From
    srs.current_outage_calls o,
    tlm.customer_electric  b,
    srs.notification_list n,
    SRS.NOTIFIABLE_CUSTOMERS_VW c,
    srs.est_customer_outages a
    Where
    c.SERVICE_ADDR_NUMBER = b.SERVICE_ADDR_NUMBER
    And substr(b.meter_number, 2, 6) = a.meter
    and b.service_point_end_date is null
    and o.meter(+)=a.meter
    and n.list_name=c.list_name';
    LOOP
    FETCH rec_ref_list INTO *strList*;
    EXIT WHEN rec_ref_list%NOTFOUND;
         OPEN rec_ref_custs FOR
    'Select
    b.account_number,
    b.marketing_rep_name,
    c.customer_name, a.meter,
    a.mappole, a.feeder,
    b.last_or_corp_name,
    b.house_number,
    b.street_direction,
    b.street_name,
    b.street_suffix,
    max(odate) over (partition by b.account_number) last_called,
    n.message_type,
    c.list_name     
    From
    srs.current_outage_calls o,
    tlm.customer_electric  b,
    srs.notification_list n,
    SRS.NOTIFIABLE_CUSTOMERS_VW c,
    srs.est_customer_outages a
    Where
    c.SERVICE_ADDR_NUMBER = b.SERVICE_ADDR_NUMBER
    And substr(b.meter_number, 2, 6) = a.mete
    and b.service_point_end_date is null
    and o.meter(+)=a.meter
    and n.list_name=c.list_name
    and c.list_name = :1' using *strList*;
           LOOP
               FETCH rec_ref_custs INTO strCusts;
               EXIT WHEN rec_ref_custs%NOTFOUND;
                   StrBodyHTML:= StrBodyHTML || ', ' || strList || ', ' || strCusts;
           END LOOP;
    CLOSE rec_ref_custs;     
    END LOOP;
    CLOSE rec_ref_list;     
    You have a variable, nothing more. You DO NOT need dynamic SQL here, just trust me (then go read about it and learn why ... it will serve your career well to do some reading).
    You don't need 2 cursors here, for lack of not wanting to try to decipher this in it's entirety i took a simple hack and utilized an IN clause.
    for loop_var in
       Select
          b.account_number,
          b.marketing_rep_name,
          c.customer_name, a.meter,
          a.mappole, a.feeder,
          b.last_or_corp_name,
          b.house_number,
           b.street_direction,
          b.street_name,
          b.street_suffix,
          max(odate) over (partition by b.account_number) last_called,
          n.message_type,
          c.list_name     
       From
          srs.current_outage_calls o,
          tlm.customer_electric  b,
          srs.notification_list n,
          SRS.NOTIFIABLE_CUSTOMERS_VW c,
          srs.est_customer_outages a
       Where
        c.SERVICE_ADDR_NUMBER = b.SERVICE_ADDR_NUMBER
       And substr(b.meter_number, 2, 6) = a.mete
       and b.service_point_end_date is null
       and o.meter(+)=a.meter
       and n.list_name=c.list_name
       and c.list_name in
          Select
             c.list_name     
          From
          srs.current_outage_calls o,
          tlm.customer_electric  b,
          srs.notification_list n,
          SRS.NOTIFIABLE_CUSTOMERS_VW c,
          srs.est_customer_outages a
          Where
          c.SERVICE_ADDR_NUMBER = b.SERVICE_ADDR_NUMBER
          And substr(b.meter_number, 2, 6) = a.meter
          and b.service_point_end_date is null
          and o.meter(+)=a.meter
          and n.list_name=c.list_name
    LOOP
       StrBodyHTML:= StrBodyHTML || ', ' || loop_var.<pick_a_column_from_select_list_above>;
    END LOOP;No ref cursors, less complex and 1 single SQL query ... much cleaner and efficient.

  • ORA-00904 invalid identifier error

    Here are the steps to reproduce this. My DB version is 9i R2.
    1) create table xmlsun1 of xmltype;
    2) create table xmlsun2 as select * from xmlsun1;
    Two Tables of XML Type created successfully
    3) insert into xmlsun1 values(xmltype('<employees><employee id="35"><FirstName>Tom</FirstName><LastName>Kyte</LastName></employee></employees>'));
    4) insert into xmlsun2 values(xmltype('<employees><employee id="35"><FirstName>Tom</FirstName><LastName>Kyte</LastName></employee></employees>'));
    Now when i query, i can see one record in each tables.
    The problem is only when updation.
    5) update xmlsun1 x
    set value(x) = updatexml(value(x),'/employees/employee/@id','37')
    where existsnode(value(x),'/employees/employee[FirstName = "Tom"]') = 1;
    1 row updated
    6) update xmlsun2 x
    set value(x) = updatexml(value(x),'/employees/employee/@id','37')
    where existsnode(value(x),'/employees/employee[FirstName = "Tom"]') = 1;
    This updation fails with the error : ORA-01775: looping chain of synonyms
    I tried to change alias of xmlsun2 to y
    update xmlsun2 y
    set value(y) = updatexml(value(y),'/employees/employee/@id','37')
    where existsnode(value(y),'/employees/employee[FirstName = "Tom"]') = 1;
    I get an error saying that Y is an invalid identifier. Now, how can i update the table xmlsun2? I can't use the alias x nor any other alias.
    Thanks,
    Sundar

    I've filed bug 5560960 for this behavoir, which is still not what you are describing.. Do you have SYNONYMS defined somewhere in your example ?
    $ sqlplus scott/tiger @testcase3
    SQL*Plus: Release 9.2.0.6.0 - Production on Fri Sep 22 11:59:46 2006
    Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.6.0 - Production
    SQL> drop table xmlsun1
    2 /
    Table dropped.
    SQL> create table xmlsun1 of xmltype
    2 /
    Table created.
    SQL> drop table xmlsun2
    2 /
    Table dropped.
    SQL> create table xmlsun2 as select * from xmlsun1
    2 /
    Table created.
    SQL> insert into xmlsun1 values( xmltype ('<employees><employee id="35"><FirstName>Tom</FirstName><LastName>Kyte</LastName></employee></employees>') )
    2 /
    1 row created.
    SQL> insert into xmlsun2 values( xmltype ('<employees><employee id="35"><FirstName>Tom</FirstName><LastName>Kyte</LastName></employee></employees>') )
    2 /
    1 row created.
    SQL> update xmlsun1 x
    2 set value(x) = updatexml(value(x),'/employees/employee/@id','37')
    3 where existsnode(value(x),'/employees/employee[FirstName = "Tom"]') = 1
    4 /
    1 row updated.
    SQL> update xmlsun2 x
    2 set value(x) = updatexml(value(x),'/employees/employee/@id','37')
    3 where existsnode(value(x),'/employees/employee[FirstName = "Tom"]') = 1
    4 /
    where existsnode(value(x),'/employees/employee[FirstName = "Tom"]') = 1
    ERROR at line 3:
    ORA-00904: "X": invalid identifier
    SQL> update xmlsun2 y
    2 set value(y) = updatexml(value(y),'/employees/employee/@id','37')
    3 where existsnode(value(y),'/employees/employee[FirstName = "Tom"]') = 1
    4 /
    where existsnode(value(y),'/employees/employee[FirstName = "Tom"]') = 1
    ERROR at line 3:
    ORA-00904: "Y": invalid identifier
    SQL>

  • Help: SQL query when parsed returns Invalid Identifier error

    Hi The expression posted below is the actual SQL Expression which is required in my report:
    ((select name from (
    select loc_id,name,row_number()over(  order by r)  rn from (
    SELECT 0, loc_id, Misc1_txt  NAME,'A' STATUS ,rownum r
                        FROM dvxloc
                       WHERE loc_id = "XXXLOC"."LOC_ID"
                       union
    SELECT     parent_loc_id, loc_id, (SELECT a.Misc1_txt
                                                         FROM dvxloc a
                                                        WHERE a.loc_id =b.loc_id) NAME,'B' ,ROWNUM
                            FROM dvxlocpath b
                      START WITH b.loc_id = "XXXLOC"."LOC_ID"
                      CONNECT BY PRIOR  parent_loc_id=loc_id
    )                where name is NOT NULL        order by STATUS, R
    ) where rn = 1))
    It gives an error while parsing: "XXXLOC"."LOC_ID" invalid identifier
    LOC_ID is of numeric data type in the database. and when I run thi query in SQL editor after replacing "XXXLOC"."LOC_ID" with a numeric value say 456 . The query can be put as
    ((select name from (
    select loc_id,name,row_number()over(  order by r)  rn from (
    SELECT 0, loc_id, Misc1_txt  NAME,'A' STATUS ,rownum r
                        FROM dvxloc
                       WHERE loc_id = 456                   union
    SELECT     parent_loc_id, loc_id, (SELECT a.Misc1_txt
                                                         FROM dvxloc a
                                                        WHERE a.loc_id =b.loc_id) NAME,'B' ,ROWNUM
                            FROM dvxlocpath b
                      START WITH b.loc_id = 456                  CONNECT BY PRIOR  parent_loc_id=loc_id
    )                where name is NOT NULL        order by STATUS, R
    ) where rn = 1))
    The above query runs flawlessly in a SQL editor. and also this is parsed by the crystal sql expression editer
    I'm totally messed up of looking for altenatives. I have to deliver a report to the client and stuck on this part only.
    The below query parses perfectly in crystal:
    (select locname
    from dvxloc where loc_id in(select loc3 from dvxlocpath
    where loc_id = "XXXLOC"."LOC_ID"))
    Edited by: vipulbhatia29 on May 8, 2009 11:06 AM
    Edited by: vipulbhatia29 on May 8, 2009 11:14 AM

    You said the above works in SQL Editor but does your original work?
    ((select name from (
    select loc_id,name,row_number()over( order by r) rn from (
    SELECT 0, loc_id, Misc1_txt NAME,'A' STATUS ,rownum r
    FROM dvxloc
    WHERE loc_id = "XXXLOC"."LOC_ID"
    union
    SELECT parent_loc_id, loc_id, (SELECT a.Misc1_txt
    FROM dvxloc a
    WHERE a.loc_id =b.loc_id) NAME,'B' ,ROWNUM
    FROM dvxlocpath b
    START WITH b.loc_id = "XXXLOC"."LOC_ID"
    CONNECT BY PRIOR parent_loc_id=loc_id
    ) where name is NOT NULL order by STATUS, R
    ) where rn = 1))
    Crystal does nothing to the SQL in the command editor, what you type in is what we pass.
    What database are you connecting to? And if it has a tracing tool what SQL are you seeing from Crystal when you try to run the report?

  • Invalid identifier results from an sql statement in php

    hello there, i'm trying to access data from an oracle 11g database via oci and php 5.3.8.
    i'm getting the ORA-00904 (invalid identifier) error when executing the following statement:
    $stid = oci_parse($conn, 'select * from table1 where column1 = "XYZ"');
    when i do this:
    $searchstring = "XYZ";
    $stid = oci_parse($conn, 'select * from table1 where column1 = '.$searchstring.'');
    i'm getting this error:
    ORA-00933: SQL command not properly ended
    column1 is varchar2, the entries are either letters and numbers (never only numbers) or empty.
    when i do this:
    $stid = oci_parse($conn, 'select * from table1');
    i'm getting the data and there are entries in column1 with XYZ.
    has anyone an idea, what i do wrong?
    regards j

    The PHP forum for questions like this is at http://www.oracle.com/technetwork/forums/php/index.html
    You really need to be using a bind variable here. Otherwise you will likely suffer from poor DB performance, and also open yourself to SQL Injection security attacks. Try:
    $stid = oci_parse($conn, 'select * from table1 where column1 = :bv');
    oci_bind_by_name($stid, ":bv", $searchstring);Regarding quoting of your example try:
    $searchstring = "XYZ";
    echo  'select * from table1 where column1 = '.$searchstring.'';Then run that SQL in SQL*Plus and watch it fail. What you need is given with:
    echo  'select * from table1 where column1 = \''.$searchstring.'\'';See the bottom of p 126 of The Underground PHP and Oracle Manual
    Note that with the bind variable example you didn't need quotes around :bv.

  • 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

Maybe you are looking for

  • Firefox Keeps Crashing at random times

    What I have done but doesn't solve my problems: - I have create a new profile with firefox.exe -p - I have used Safe Mode - I have reset my firefox - I am using the latest Firefox - I am using the latest Flash - I have disabled the hardware accelerat

  • Where can i buy a new display for my iPhone 4?

    My display (juste the lens) has broke. It can be fixed? Where can i buy a new one? Anyone knows if the white display fits on the black iPhone 4? Tks from Brazil

  • Rollup Getting Delayed

    Hi All, I am doing the Rollup for ZIC_C03 cube manually,the problem is after execute the Rollup it is getting delayed to complete. I have started one job on 02/01/06 that particular job is still in active mode in SM37 and while trying to cancel the j

  • No DAD configuration Found

    Please if somebody can help. My TNS Listener is running and database us up.Connecting to portal home page is giving me "Proxy log on failed" together with the message "TNS could not resolve service name" In http://192.168.1.101/pls/portal30/admin_/da

  • ORA-15020: discovered duplicate ASM disk

    Hello. I am installing Oracle GI and Rdbms 11.2.0.3+, and when the installer is creating the diskgroup fail with the error ORA-15020: discovered duplicate ASM disk. INFO: Read: Configuring ASM failed with the following message: INFO: Read: One or mor