Solved

Invalid identifier plsql error

Posted on 2004-04-20
9
869 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

717 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