-1

I have the following code:

if USER IN (SELECT user_id from user_maint where roll = 12) THEN
        p_status := 'W';

ELSE 
        p_status := 'A';
END IF;

It gives the error: Error(332,16): PLS-00405: subquery not allowed in this context

How to make subquery in the IF clause?

Imran Hemani
  • 599
  • 3
  • 12
  • 27

1 Answers1

3

Select first, use in if next.

declare
  l_user_id user_maint.user_id%type;
  p_status  varchar2(1);
begin
  select user_id
  into l_user_id
  from user_maint
  where roll = 12;

  if l_user_id = user then
     p_status := 'W';
  else
     p_status := 'A';
  end if;
end;
/

Though, a simpler option is

select case when user_id = user then 'W'
            else 'A'
       end
into p_status
from user_maint
where roll = 12;
Littlefoot
  • 131,892
  • 15
  • 35
  • 57