Solved

Invalid identifier plsql error

Posted on 2004-04-20
9
868 Views
Last Modified: 2012-05-04
Please urgent help!!!, I have a procedure, but I don't know why I have the error "Invalid Identifier", my declaration is in this way:
                     
  strsql            VARCHAR2 (4000);
 
      strsql := strsql || 'SELECT * FROM TAB_FIRST WHERE  ';
      strsql := strsql || 'B.CODSTATUS    = D.CODSTATUS   AND ';
      strsql := strsql || 'A.CODTODO      = F.CODTODO     AND ';
      strsql := strsql || 'A.USERFROM     = E.CODI_OPER   AND ';
      strsql := strsql || 'A.OPERTYPEFROM = E.TIPO_OPER  AND ';
      strsql := strsql || 'J.TIPO         = ''A3''        AND ';
      strsql := strsql || 'A.OPERTYPEFROM = J.CODIGO  AND ';
      strsql := strsql || 'A.CODSTAGE     = G.CODSTAGE    AND ';
      strsql := strsql || 'A.CODSTAGE     = H.CODSTAGE    AND ';
      strsql := strsql || 'A.PERSONTYPE   = H.PERSONTYPE  AND ';
      ........

well, is a very large query and when it has a lenght of 1250 characters the next line presents the invalid identifier error for strsql, can you help me? do you know or have any idea of what's happening? I know that the max lenght is 400 for a varchar2 type.  Thanks
0
Comment
Question by:mahine
9 Comments
 
LVL 9

Expert Comment

by:pratikroy
ID: 10870059
You are refering to table aliases A, B, D, F, E, J, G, H etc, but in your first line you just have 'SELECT * FROM TAB_FIRST WHERE  '. Where are the other tables ? I think you have missed out selecting from all other tables and mentioning their aliases.

Once you do that you should be able to run your query without problems.

Hope this helps
0
 
LVL 9

Expert Comment

by:pratikroy
ID: 10870076
Best way to identify the problem with your query is, to do a DBMS_OUTPUT of the strsql (variable that has your SQL statement), before doing and 'EXECUTE' on it.

Note that there is a limit of 255 characters (in one line) in DBMS_OUTPUT.

Hope this would also help.
0
 

Author Comment

by:mahine
ID: 10870195
Well that's right the sql query is malformed but i's because I did not write it all, I put only a piece to have the idea, but in real it's well, I have defined the tables and synonims and everything, I am making debug but when I debug it I can see the invalid identifier too, the dbms_ouput presents just until the line before the error message obviously, I thanks your comments but I need more suggestions if you have some please post a comment thanks
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:seazodiac
ID: 10870744
This is the problem, you cannot use double quote for literal:
like in this line:

    strsql := strsql || 'J.TIPO         = ''A3''        AND ';


you should write it with the single quote instead :

    strsql := strsql || 'J.TIPO         = '''A3'''        AND ';
0
 
LVL 23

Accepted Solution

by:
seazodiac earned 125 total points
ID: 10870748
yes, three single quotes in a row is needed for escaping one single quote
0
 
LVL 9

Expert Comment

by:pratikroy
ID: 10873143
You can take care of the double quotes problem as suggested by seazodiac

you might want to use the CHR(39), which is same as ' character.

So replace your statement
strsql := strsql || 'J.TIPO         = ''A3''        AND ';
to
strsql := strsql || 'J.TIPO         = ' || chr(39)||'A3'||chr(39) || ' AND ';

Just in case if you still get the problem, can you try and do the DBMS_OUTPUT and see what's the SQL that is getting generated ?

Since there is a limit of 255 characters in DBMS_OUTPUT, you might want to print all the characters in your strsql in chunks of 255 characters.

If you identify the SQL, you can try and execute the SQL statement from SQL*Plus window.

You might want to break the logic of printing the SQL statement by doing the DBMS_OUTPUT in a loop :

a:=1;
while a<length(strsql)
loop
dbms_output.put_line(strsql,a,255);
a:=a+255;
end loop;

remember to declare variable a in the declaration section.

You will get invalid identifier, only when you reach the 'EXECUTE ..' statement. You can do this DBMS_OUTPUT before doing the EXECUTE. Once you get the complete SQL statement, try and run it from SQL*Plus. It should tell you exactly which line is having the problem. Then you should be able to find out the cause of real problem. It might be diffcult for us to identify the real problem, without seeing the actual SQL statement that would be executed using the EXECUTE. Moreover to make it harder, you have given us a malformed SQL statement, due to which we are'nt sure whether its a problem of your SQL statement, or something else.

If you continue to face the same problem, Can you post the complete SQL statement after you get it as the output from the above DBMS_OUTPUT statements ?
0
 
LVL 8

Expert Comment

by:annamalai77
ID: 10875016
hi there

the error is in the line below

strsql := strsql || 'J.TIPO         = ''A3''        AND ';

just replace it with this line

strsql := strsql || 'J.TIPO = ' || "A3" || ' AND ';

regards
annamalai;
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question