Home » SQL & PL/SQL » SQL & PL/SQL » Unable to solve PLS-00103 error
Unable to solve PLS-00103 error [message #158231] Thu, 09 February 2006 05:48 Go to next message
sreedevi_83
Messages: 43
Registered: October 2005
Location: India
Member
Hi Friends,
I would like to state an example situation of my problem.
I have written a small pl/sql code which ran succesfully.It prints 9 order numbers.
SQL> DECLARE
  2  s VARCHAR2(200);
  3  n number;
  4  
  5  BEGIN
  6  
  7  FOR  i in (SELECT order_number FROM oe_order_headers_all WHERE rownum<10) LOOP
  8  DBMS_OUTPUT.PUT_LINE(i.order_number);
  9  END LOOP;
 10  
 11  
 12  END;
 13  /
1
1
2
2
3
3
4
5
6

PL/SQL procedure successfully completed.


Now I want to print ordernumbers along with some information which is fetched from some sql statement. Here i m just siting an example. But in the real situation i have to write a select statement in cursor which involves many subqueries.
Here is the code which gave me an error.
SQL> DECLARE
  2  BEGIN
  3  
  4  FOR  i in (SELECT order_number||'.'||(SELECT level
  5            FROM DUAL
  6            CONNECT BY level=1) 
  7      FROM oe_order_headers_all WHERE rownum<10) LOOP
  8  DBMS_OUTPUT.PUT_LINE(i.order_number);
  9  END LOOP;
 10  END;
 11  
 12  /
DECLARE
*
ERROR at line 1:
ORA-06550: line 4, column 39:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + case mod new not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe


I want to know why this error has arised and in what way can i avoid this error.
here the output should be
1.1
1.1
2.1
3.1
...and so on
In real situation I have come across a situation where I need to get some information using select query and concatenate to existing inf that is fetched in select query of cursor. can anybody help me how to avoid this error and get the problem solved?

Thanks in advance,
Sreedevi
Re: Unable to solve PLS-00103 error [message #158233 is a reply to message #158231] Thu, 09 February 2006 06:11 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9106
Registered: November 2002
Location: California, USA
Senior Member
You need to provide an alias for the concatenated column.

scott@ORA92> DECLARE
  2  BEGIN
  3    FOR i IN (SELECT deptno
  4                     || '.'
  5                     || (SELECT  level
  6                         FROM    DUAL
  7                         CONNECT BY level = 1)
  8                       AS some_alias
  9              FROM   dept
 10              WHERE  ROWNUM < 10)
 11    LOOP
 12      DBMS_OUTPUT.PUT_LINE (i.some_alias);
 13    END LOOP;
 14  END;
 15  /
10.1
20.1
30.1
40.1
50.1

PL/SQL procedure successfully completed.

Re: Unable to solve PLS-00103 error [message #158236 is a reply to message #158233] Thu, 09 February 2006 06:20 Go to previous messageGo to next message
sreedevi_83
Messages: 43
Registered: October 2005
Location: India
Member
Thank you. But still I could not sovle the issue.
I use 8.0.6 version. is it a version problem?
SQL> DECLARE
  2  s VARCHAR2(200);
  3  n number;
  4  
  5  BEGIN
  6  
  7  FOR  i in (SELECT order_number||'.'||(SELECT level FROM DUAL  CONNECT BY level=1) as a
  8      FROM oe_order_headers_all WHERE rownum<10) LOOP
  9  DBMS_OUTPUT.PUT_LINE(i.a);
 10  END LOOP;
 11  
 12  END;
 13  /
DECLARE
*
ERROR at line 1:
ORA-06550: line 7, column 39:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + case mod new not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe


SQL> 
Re: Unable to solve PLS-00103 error [message #158238 is a reply to message #158236] Thu, 09 February 2006 06:28 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9106
Registered: November 2002
Location: California, USA
Senior Member
Yes, it's a version problem. That is way out of date. The oldest currently supported version is 9i. 8.0 had lots of restrictions, including not being able to join hierarchical queries. You may need to do something like this:

scott@ORA92> DECLARE
  2  BEGIN
  3    FOR i IN (SELECT deptno
  4              FROM   dept)
  5    LOOP
  6      FOR j IN
  7        (SELECT empno
  8         FROM   emp
  9         WHERE  deptno = i.deptno)
 10      LOOP
 11        DBMS_OUTPUT.PUT_LINE (i.deptno || '.' || j.empno);
 12      END LOOP;
 13    END LOOP;
 14  END;
 15  /
10.7782
10.7839
10.7934
20.7369
20.7566
20.7788
20.7876
20.7902
30.7499
30.7521
30.7654
30.7698
30.7844
30.7900

PL/SQL procedure successfully completed.

Re: Unable to solve PLS-00103 error [message #158242 is a reply to message #158238] Thu, 09 February 2006 06:45 Go to previous messageGo to next message
sreedevi_83
Messages: 43
Registered: October 2005
Location: India
Member
Thank you very much. Here subquery is a simple independent select query and hence you have suggested this way. But my query is a very complex one with many subqueries which are interdependent. I tried to use a ref cursor and it worked fine.
Here is the code
SQL> DECLARE
  2  s VARCHAR2(200);
  3  TYPE rcur IS REF CURSOR;      
  4  cur rcur; 
  5  writestring VARCHAR2(30);
  6  
  7  BEGIN
  8  s:='SELECT order_number||''.''||(SELECT level FROM DUAL  CONNECT BY level=1) as a
  9      FROM oe_order_headers_all WHERE rownum<10';
 10  
 11  OPEN cur FOR s;
 12  
 13  LOOP
 14             FETCH cur INTO writestring;
 15  EXIT WHEN cur%NOTFOUND;       
 16  DBMS_OUTPUT.PUT_LINE(writestring);
 17  END LOOP;
 18  
 19  END;
 20  /
1.1
1.1
2.1
2.1
3.1
3.1
4.1
5.1
6.1

PL/SQL procedure successfully completed.

SQL> 
Re: Unable to solve PLS-00103 error [message #158243 is a reply to message #158242] Thu, 09 February 2006 06:52 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9106
Registered: November 2002
Location: California, USA
Senior Member
When you open a ref cursor dynamically, as you did, it cause Oracle to use the SQL engine, instead of the PL/SQL engine. In earlier versions of Oracle, there were vast differences between the two and far fewer restrictions with the SQL engine.
Re: Unable to solve PLS-00103 error [message #158245 is a reply to message #158243] Thu, 09 February 2006 07:02 Go to previous message
sreedevi_83
Messages: 43
Registered: October 2005
Location: India
Member
Thank you very much for valuable information.
Thanks,
Sreedevi
Previous Topic: After Logon Trigger error "ORA-06502: PL/SQL: numeric or value error"
Next Topic: Recursive Object types
Goto Forum:
  


Current Time: Sun Sep 07 00:01:38 CDT 2025