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

Hello,

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?

Thanks!
ccorrenteAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
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:
============================================================
declare
      myval      char(1) := 'X';
      isThere      char(1) ;
begin

      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;

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

end;
/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.