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

Posted on 2004-11-18
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 76

    Accepted Solution

    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

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Oracle Cursor 5 50
    find difference between dates from a column in oracle 9 40
    Oracle 12c 10 84
    SSN Format in Oracle 2 38
    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…
    I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
    This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
    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.

    733 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

    17 Experts available now in Live!

    Get 1:1 Help Now