"PLS-00405: subquery not allowed in this context" Error

Posted on 2004-11-18
Medium Priority
Last Modified: 2011-10-03

I am trying to compile my oracle stored proc, but the code keeps erroring on the following line:

elsif v_CODE NOT IN (Select CODE from CODE_TBL) then

I get an  "PLS-00405: subquery not allowed in this context" error.  If I run the embedded select statement in SQL+, it works fine, so I know the problem is not that the select statement is wrong

Is what I am trying to do not allowed?  If it's  not allowed, is there another way to do it?

Question by:ccorrente
1 Comment
LVL 78

Accepted Solution

slightwv (䄆 Netminder) earned 500 total points
ID: 12614320
Per the DOCS, you can't do this:

PLS-00405: subquery not allowed in this context
Cause: A subquery was used in an inappropriate context, such as: if (SELECT deptno FROM emp WHERE ... ) = 20 then ... Subqueries are allowed only in SQL statements.

Action: The same result can be obtained by using a temporary variable, as in: SELECT deptno INTO temp_var FROM emp WHERE ...; IF temp_var = 20 THEN ...

You will need to re-write the proc something like:
      myval      char(1) := 'X';
      isThere      char(1) ;

      select 'Y' into isThere from dual where myval not in (select dummy from dual);

      if myval <> 'Y' then
            dbms_output.put_line('Got it');
      end if;

            when no_data_found then
                  dbms_output.put_line('Did''t get it');


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses

839 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