Solved

Invalid identifier plsql error

Posted on 2004-04-20
9
856 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
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.

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now